Statistics

Problem Statement for "WaiterTipping"

Problem Statement

You have just finished eating your Chinese food, and the waiter has brought you the bill. You note the untaxed total on the bill, given as an int in total. Additionally, you know the tax rate in your locale, given as an int in taxPercent. Lastly, you have counted how much money you have, given as an int in money.

Since you feel the service was excellent, you want to give as large a tip as you can afford. You are to return the largest integral value of tip such that:
total + floor(total*taxPercent/100) + floor(total*tip/100) <= money
If there is no non-negative value of tip that satisfies the above inequality, return -1 (you don't have enough money to pay the bill and tax).

Definition

Class:
WaiterTipping
Method:
maxPercent
Parameters:
int, int, int
Returns:
int
Method signature:
int maxPercent(int total, int taxPercent, int money)
(be sure your method is public)

Notes

  • total and money are given in cents
  • Although certainly unusual, it is perfectly permissible to leave a tip that is larger than the original bill.

Constraints

  • total and money will be between between 100 and 100000, inclusive.
  • taxPercent will be between 0 and 100, inclusive.

Examples

  1. 500

    10

    600

    Returns: 10

    Here, you pay 500 for the bill and 50 for tax, leaving you 50 for the tip, which is 10% of the original bill total.

  2. 500

    10

    604

    Returns: 10

    Similar to above, but here you have 54 cents for tip, but this will still only get you 10%.

  3. 850

    8

    870

    Returns: -1

    Uh-oh, looks like you don't have enough money!

  4. 23975

    13

    27834

    Returns: 3

  5. 53039

    96

    6297

    Returns: -1

  6. 8288

    2

    40158

    Returns: 382

  7. 5753

    19

    7189

    Returns: 5

  8. 6526

    13

    6037

    Returns: -1

  9. 4333

    12

    13999

    Returns: 211

  10. 4839

    16

    14498

    Returns: 183

  11. 4115

    16

    6257

    Returns: 36

  12. 4866

    19

    13398

    Returns: 156

  13. 5051

    19

    13364

    Returns: 145

  14. 3637

    16

    10242

    Returns: 165

  15. 3296

    17

    6830

    Returns: 90

  16. 2481

    16

    12440

    Returns: 385

  17. 126

    40

    950

    Returns: 615

  18. 267

    56

    701

    Returns: 107

  19. 212

    25

    947

    Returns: 322

  20. 107

    15

    589

    Returns: 436

  21. 166

    98

    409

    Returns: 49

  22. 167

    97

    371

    Returns: 26

  23. 102

    18

    281

    Returns: 158

  24. 424

    82

    1093

    Returns: 76

  25. 206

    87

    671

    Returns: 139

  26. 194

    30

    779

    Returns: 272

  27. 256

    16

    912

    Returns: 241

  28. 128

    67

    526

    Returns: 245

  29. 248

    3

    1065

    Returns: 327

  30. 127

    90

    493

    Returns: 199

  31. 783

    5

    1072

    Returns: 32

  32. 226

    48

    584

    Returns: 111

    226 + floor(226*48/100) + floor(226*111/100) = 226 + floor(10848/100) + floor(25086/100) = 226 + 108 + 250 = 584

  33. 281

    24

    558

    Returns: 75

  34. 123

    52

    696

    Returns: 415

    123 + floor(123*52/100) + floor(123*415/100) = 123 + floor(6396/100) + floor(51045/100) = 123 + 63 + 510 = 696

  35. 100

    0

    100000

    Returns: 99900

  36. 500

    10

    550

    Returns: 0

  37. 500

    10

    604

    Returns: 10

  38. 123

    52

    696

    Returns: 415

  39. 226

    48

    584

    Returns: 111

  40. 100

    0

    100000

    Returns: 99900

  41. 100

    10

    1000

    Returns: 890


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: