PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: notsoloud
Tester: mexomerf
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
Chef has Y coins, a gym membership costs X.
Chef can spend one coin to attend a trial session, which gets him a D\% discount on the membership.
Find the minimum number of trials Chef must attend to be able to afford a membership.
EXPLANATION:
Suppose Chef attends exactly k trials, and then buys a membership.
He then receives a total discount of (k\cdot D)\% on the membership cost, while spending k coins beforehand.
So, the total cost to Chef is
If this quantity is \leq Y, Chef can afford it; otherwise he cannot.
Chef cannot attend more than Y trials (since he can’t spend more than Y coins), so simply try every k = 0, 1, 2, \ldots, Y and find the first one among them such that
If they all fail the check, the answer is -1.
TIME COMPLEXITY:
\mathcal{O}(Y) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
d, x, y = map(int, input().split())
ans = -1
for i in range(y+1):
coins = y - i
discount = i*d*x/100
if coins >= x - discount:
ans = i
break
print(ans)