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.
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