Statistics

Problem Statement for "TippingWaiters"

Problem Statement

In a restaurant, if you were pleased by the waiter's service, you may leave him a tip -- you pay him more than the actual value of the bill, and the waiter keeps the excess money. In some countries, not leaving a tip for the waiter is even considered impolite. During my recent holiday I was having dinner in a foreign restaurant. The pamphlet from my travel agency informed me that the proper way of tipping the waiter is the following:
  • The sum I pay must be round, i.e., divisible by 5.
  • The tip must be between 5% and 10% of the final sum I pay, inclusive.
Clearly, sometimes there may be multiple "correct" ways of settling the bill. I'd like to know exactly how many choices I have in a given situation. I could program it easily, but I was having a holiday... and so it's you who has to solve this task. You will be given:
  • an int bill -- the amount I have to pay for the dinner
  • an int cash -- the amount of money I have in my pocket
Write a function that computes how many different final sums satisfy the conditions above.

Definition

Class:
TippingWaiters
Method:
possiblePayments
Parameters:
int, int
Returns:
int
Method signature:
int possiblePayments(int bill, int cash)
(be sure your method is public)

Notes

  • Assume that both bill and cash are in dollars.
  • All the money I have is in one-dollar banknotes.

Constraints

  • bill and cash are between 1 and 2,000,000,000, inclusive.
  • bill doesn't exceed cash.

Examples

  1. 4

    100

    Returns: 0

    4 isn't a round sum, and 5 is too much.

  2. 23

    100

    Returns: 1

    The only correct choice is to pay 25 dollars, thus leaving a tip of 2 dollars.

  3. 23

    24

    Returns: 0

    The same bill, but I don't have enough money to leave an appropriate tip.

  4. 220

    239

    Returns: 1

    This time, it is appropriate to pay either 235 or 240 dollars. Sadly, I don't have enough money for the second possibility.

  5. 1234567

    12345678

    Returns: 14440

    A large bill, but with that much money I don't care.

  6. 1880000000

    1980000000

    Returns: 210527

  7. 1

    2000000000

    Returns: 0

  8. 2000000000

    2000000000

    Returns: 0

  9. 1000000000

    2000000000

    Returns: 11695907

  10. 1800000000

    2000000000

    Returns: 21052632

  11. 21345

    21532156

    Returns: 250

  12. 1

    1

    Returns: 0

  13. 1

    2

    Returns: 0

  14. 1

    5

    Returns: 0

  15. 5

    5

    Returns: 0

  16. 5

    10

    Returns: 0

  17. 10000

    100000

    Returns: 117

  18. 10000

    11000

    Returns: 95

  19. 123456789

    234567890

    Returns: 1443940

  20. 123456789

    133456789

    Returns: 700455

  21. 17100

    19000

    Returns: 201

  22. 17100

    18000

    Returns: 1

  23. 171000000

    181000000

    Returns: 200001

  24. 171000000

    190000000

    Returns: 2000001

  25. 171000000

    189999999

    Returns: 2000000

  26. 171000000

    180000001

    Returns: 1

  27. 171000000

    179999999

    Returns: 0

  28. 1880000000

    1980000000

    Returns: 210527

  29. 2000000

    2000000000

    Returns: 23392

  30. 1

    2000000000

    Returns: 0

  31. 1234567

    12345678

    Returns: 14440

  32. 23

    100

    Returns: 1

  33. 190

    200

    Returns: 1

  34. 1900000000

    2000000000

    Returns: 1

  35. 1500000000

    2000000000

    Returns: 17543860

  36. 188084

    1980605100

    Returns: 2200

  37. 18800000

    1980000000

    Returns: 219883

  38. 199999999

    199999999

    Returns: 0

  39. 18

    1980605100

    Returns: 1

  40. 1750000000

    2000000000

    Returns: 20467836

  41. 1900

    1000000

    Returns: 23

  42. 100

    2000000000

    Returns: 1

  43. 1645665466

    1999999999

    Returns: 19247549

  44. 19

    164

    Returns: 1

  45. 3243642

    2000000000

    Returns: 37938

  46. 1000000000

    2000000000

    Returns: 11695907

  47. 5

    200000000

    Returns: 0

  48. 100

    200

    Returns: 1

  49. 23

    2000000000

    Returns: 1

  50. 855

    1980000000

    Returns: 11

  51. 950

    20000

    Returns: 12


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: