ThreeIncreasing
SRM 706 · 2016-12-07 · by Errichto
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
Constraints
- a, b and c will each be between 1 and 3000, inclusive.
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.
Submissions are judged against all 55 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ThreeIncreasing with a public method int minEaten(int a, int b, int c) · 55 test cases · 2 s / 256 MB per case