Statistics

Problem Statement for "ThreeIncreasing"

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 ints a, b, and c. Compute and return the smallest possible number of candies Limak should eat in order to make his three boxes look nice. If he has no way to make his boxes look nice, return -1 instead.

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

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

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

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

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

  5. 4

    2

    6

    Returns: 3

    Limak can eat 3 candies from the first box.

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

  7. 2789

    2400

    1693

    Returns: 1806

  8. 1

    1

    1

    Returns: -1

  9. 1

    1

    2

    Returns: -1

  10. 1

    1

    3

    Returns: -1

  11. 1

    2

    3

    Returns: 0

  12. 1

    3

    1

    Returns: -1

  13. 1

    3

    2

    Returns: -1

  14. 1

    3

    3

    Returns: 1

  15. 2

    1

    1

    Returns: -1

  16. 2

    2

    2

    Returns: -1

  17. 2

    1

    3

    Returns: -1

  18. 2

    3

    1

    Returns: -1

  19. 2

    3000

    3000

    Returns: 1

  20. 2

    2

    3000

    Returns: 1

  21. 3

    3

    3

    Returns: 3

  22. 3

    2

    2

    Returns: -1

  23. 3

    2

    3

    Returns: 2

  24. 1234

    1

    2135

    Returns: -1

  25. 3000

    3

    1

    Returns: -1

  26. 213

    3

    2

    Returns: -1

  27. 3000

    3000

    3000

    Returns: 3

  28. 3000

    3000

    1

    Returns: -1

  29. 3000

    3000

    2

    Returns: -1

  30. 3000

    3000

    3

    Returns: 5997

  31. 3000

    2999

    2998

    Returns: 6

  32. 3000

    2998

    2999

    Returns: 3

  33. 2999

    3000

    3000

    Returns: 2

  34. 2999

    3000

    2999

    Returns: 4

  35. 3000

    3000

    1

    Returns: -1

  36. 2974

    1834

    2900

    Returns: 1141

  37. 100

    1

    102

    Returns: -1

  38. 100

    3000

    102

    Returns: 2899

  39. 100

    100

    102

    Returns: 1

  40. 100

    101

    102

    Returns: 0

  41. 100

    102

    102

    Returns: 1

  42. 123

    1500

    2500

    Returns: 0

  43. 123

    2500

    1500

    Returns: 1001

  44. 3000

    1500

    1500

    Returns: 1503

  45. 100

    10

    10

    Returns: 93

  46. 10

    300

    300

    Returns: 1

  47. 4

    4

    4

    Returns: 3

  48. 1

    50

    50

    Returns: 1

  49. 7

    6

    4

    Returns: 8

  50. 6

    6

    5

    Returns: 5

  51. 3

    3

    5

    Returns: 1

  52. 3

    4

    3

    Returns: 4

  53. 1

    2

    2

    Returns: -1

  54. 1

    2

    1

    Returns: -1

  55. 4

    7

    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: