Statistics

Problem Statement for "TriangleMaking"

Problem Statement

You have three sticks. Their current lengths are a, b, and c. You can shorten each of those sticks arbitrarily. Your goal is to produce three sticks with the following properties:
  • The length of each stick is a positive integer.
  • The three sticks can be used to build a triangle. The triangle must be non-degenerate. (I.e., it must have a positive area.)
  • The perimeter of the triangle must be as large as possible.
You are given the ints a, b, and c. Compute and return the largest possible perimeter of the triangle constructed from your three sticks.

Definition

Class:
TriangleMaking
Method:
maxPerimeter
Parameters:
int, int, int
Returns:
int
Method signature:
int maxPerimeter(int a, int b, int c)
(be sure your method is public)

Notes

  • The return value is always defined. In other words, for any a, b, and c there is at least one way to build a valid triangle.

Constraints

  • a will be between 1 and 100, inclusive.
  • b will be between 1 and 100, inclusive.
  • c will be between 1 and 100, inclusive.

Examples

  1. 1

    2

    3

    Returns: 5

    Shorten the last stick from 3 to 2. There is a triangle with sides (1,2,2). The perimeter of this triangle is 1+2+2 = 5.

  2. 2

    2

    2

    Returns: 6

    Here the optimal solution is to use the three sticks you have without shortening any of them.

  3. 1

    100

    1

    Returns: 3

  4. 41

    64

    16

    Returns: 113

  5. 7

    35

    12

    Returns: 37

  6. 99

    53

    35

    Returns: 175

  7. 14

    5

    49

    Returns: 37

  8. 69

    72

    43

    Returns: 184

  9. 44

    7

    21

    Returns: 55

  10. 18

    44

    72

    Returns: 123

  11. 21

    1

    56

    Returns: 43

  12. 49

    9

    1

    Returns: 19

  13. 41

    94

    58

    Returns: 193

  14. 14

    6

    12

    Returns: 32

  15. 86

    19

    17

    Returns: 71

  16. 62

    27

    78

    Returns: 167

  17. 82

    68

    73

    Returns: 223

  18. 41

    2

    51

    Returns: 85

  19. 66

    5

    98

    Returns: 141

  20. 34

    22

    77

    Returns: 111

  21. 44

    3

    59

    Returns: 93

  22. 2

    46

    62

    Returns: 95

  23. 30

    70

    100

    Returns: 199

  24. 60

    6

    66

    Returns: 131

  25. 54

    1

    61

    Returns: 109

  26. 11

    56

    67

    Returns: 133

  27. 10

    70

    100

    Returns: 159

  28. 56

    8

    72

    Returns: 127

  29. 39

    55

    100

    Returns: 187

  30. 72

    18

    95

    Returns: 179

  31. 48

    29

    95

    Returns: 153

  32. 35

    65

    100

    Returns: 199

  33. 1

    1

    1

    Returns: 3

  34. 100

    100

    100

    Returns: 300

  35. 10

    2

    2

    Returns: 7

  36. 2

    3

    5

    Returns: 9

  37. 2

    2

    4

    Returns: 7

  38. 3

    4

    5

    Returns: 12

  39. 2

    4

    6

    Returns: 11

  40. 2

    3

    3

    Returns: 8


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: