TopcoderArchiveVisit Topcoder
SRM20 Nov 2004
SRM 219

WaiterTipping

Problem statement, definition, constraints, and public examples.

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. 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
  5. 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
  6. 500
    10
    550
    Returns: 0
Back to all problems