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).
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
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
8288
2
40158
Returns: 382
5753
19
7189
Returns: 5
6526
13
6037
Returns: -1
4333
12
13999
Returns: 211
4839
16
14498
Returns: 183
4115
16
6257
Returns: 36
4866
19
13398
Returns: 156
5051
19
13364
Returns: 145
3637
16
10242
Returns: 165
3296
17
6830
Returns: 90
2481
16
12440
Returns: 385
126
40
950
Returns: 615
267
56
701
Returns: 107
212
25
947
Returns: 322
107
15
589
Returns: 436
166
98
409
Returns: 49
167
97
371
Returns: 26
102
18
281
Returns: 158
424
82
1093
Returns: 76
206
87
671
Returns: 139
194
30
779
Returns: 272
256
16
912
Returns: 241
128
67
526
Returns: 245
248
3
1065
Returns: 327
127
90
493
Returns: 199
783
5
1072
Returns: 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
281
24
558
Returns: 75
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
100
0
100000
Returns: 99900
500
10
550
Returns: 0
500
10
604
Returns: 10
123
52
696
Returns: 415
226
48
584
Returns: 111
100
0
100000
Returns: 99900
100
10
1000
Returns: 890