Problem Statement
- 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.
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
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
Returns: 6
Here the optimal solution is to use the three sticks you have without shortening any of them.
1
100
1
Returns: 3
41
64
16
Returns: 113
7
35
12
Returns: 37
99
53
35
Returns: 175
14
5
49
Returns: 37
69
72
43
Returns: 184
44
7
21
Returns: 55
18
44
72
Returns: 123
21
1
56
Returns: 43
49
9
1
Returns: 19
41
94
58
Returns: 193
14
6
12
Returns: 32
86
19
17
Returns: 71
62
27
78
Returns: 167
82
68
73
Returns: 223
41
2
51
Returns: 85
66
5
98
Returns: 141
34
22
77
Returns: 111
44
3
59
Returns: 93
2
46
62
Returns: 95
30
70
100
Returns: 199
60
6
66
Returns: 131
54
1
61
Returns: 109
11
56
67
Returns: 133
10
70
100
Returns: 159
56
8
72
Returns: 127
39
55
100
Returns: 187
72
18
95
Returns: 179
48
29
95
Returns: 153
35
65
100
Returns: 199
1
1
1
Returns: 3
100
100
100
Returns: 300
10
2
2
Returns: 7
2
3
5
Returns: 9
2
2
4
Returns: 7
3
4
5
Returns: 12
2
4
6
Returns: 11
2
3
3
Returns: 8