WaiterTipping
SRM 219 · 2004-11-20 · by erinn
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
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).
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.
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.
500 10 604 Returns: 10
Similar to above, but here you have 54 cents for tip, but this will still only get you 10%.
850 8 870 Returns: -1
Uh-oh, looks like you don't have enough money!
23975 13 27834 Returns: 3
53039 96 6297 Returns: -1
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
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
Submissions are judged against all 41 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WaiterTipping with a public method int maxPercent(int total, int taxPercent, int money) · 41 test cases · 2 s / 256 MB per case