Problem Statement
Bear Limak has three boxes arranged in a row. The first box currently contains a candies, the second one contains b candies, and the third one contains c candies.
Limak thinks that the three boxes would look nice if they had the following two properties:
- Each box should contain at least one candy.
- The numbers of candies should form a strictly increasing sequence. In other words, the first box should contain fewer candies than the second box, and the second box should contain fewer candies than the third one.
Limak can only modify the current content of the boxes in one way: he can eat some of the candies.
You are given the
Definition
- Class:
- ThreeIncreasing
- Method:
- minEaten
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int minEaten(int a, int b, int c)
- (be sure your method is public)
Constraints
- a, b and c will each be between 1 and 3000, inclusive.
Examples
15
40
22
Returns: 19
Limak can eat 19 candies from the second box. Numbers of candies will form a strictly increasing sequence {15, 21, 22}. Limak can't achieve a strictly increasing sequence after eating fewer than 19 candies, so the answer is 19.
5
6
6
Returns: 2
Note that in a strictly increasing sequence every number should be strictly lower than the next number (ties are not allowed). Here, Limak can eat 1 candy from the first box and 1 candy from the second box, which results in a sequence {4, 5, 6}. The answer is 2 because Limak eats 2 candies.
6
1
3000
Returns: -1
Here, the second box contains only 1 candy. The first box should contain a smaller number of candies so Limak would have to eat all candies there. A box can't become empty though, so the answer is -1.
6
4
2
Returns: -1
As in the previous example, Limak cannot produce a strictly increasing sequence of candy counts without emptying one of the boxes.
4
2
6
Returns: 3
Limak can eat 3 candies from the first box.
1
1234
3000
Returns: 0
Limak doesn't have to eat any candies. Boxes aren't empty and the sequence {1, 1234, 3000} is strictly increasing.
2789
2400
1693
Returns: 1806
1
1
1
Returns: -1
1
1
2
Returns: -1
1
1
3
Returns: -1
1
2
3
Returns: 0
1
3
1
Returns: -1
1
3
2
Returns: -1
1
3
3
Returns: 1
2
1
1
Returns: -1
2
2
2
Returns: -1
2
1
3
Returns: -1
2
3
1
Returns: -1
2
3000
3000
Returns: 1
2
2
3000
Returns: 1
3
3
3
Returns: 3
3
2
2
Returns: -1
3
2
3
Returns: 2
1234
1
2135
Returns: -1
3000
3
1
Returns: -1
213
3
2
Returns: -1
3000
3000
3000
Returns: 3
3000
3000
1
Returns: -1
3000
3000
2
Returns: -1
3000
3000
3
Returns: 5997
3000
2999
2998
Returns: 6
3000
2998
2999
Returns: 3
2999
3000
3000
Returns: 2
2999
3000
2999
Returns: 4
3000
3000
1
Returns: -1
2974
1834
2900
Returns: 1141
100
1
102
Returns: -1
100
3000
102
Returns: 2899
100
100
102
Returns: 1
100
101
102
Returns: 0
100
102
102
Returns: 1
123
1500
2500
Returns: 0
123
2500
1500
Returns: 1001
3000
1500
1500
Returns: 1503
100
10
10
Returns: 93
10
300
300
Returns: 1
4
4
4
Returns: 3
1
50
50
Returns: 1
7
6
4
Returns: 8
6
6
5
Returns: 5
3
3
5
Returns: 1
3
4
3
Returns: 4
1
2
2
Returns: -1
1
2
1
Returns: -1
4
7
3
Returns: 8