PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: tabr
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
You are M minutes into a 300-minute contest, with a penalty of P and one problem left to solve.
Making a correct submission at time X gives you an additional penalty of X.
Making a wrong submission at time X gives you an additional penalty of 20, and you must wait one minute before making the next submission.
You want to both solve the problem before the 300-th minute, and also ensure your total penalty is \leq 1000.
What’s the maximum number of wrong submissions you can make?
EXPLANATION:
Suppose you fix k, the number of wrong submissions you make.
Then, since you have to wait a minute between each of them, it’s best to make them at minutes
M, M+1, M+2, \ldots, M+k-1
Following this, you can make a correct submission at time M+k to solve the problem.
The total increase to our penalty is 20\cdot k + (M+k): 20 for each wrong submission, and M+k for the final correct one.
There are two things to ensure here:
- The correct submission should be within the 300-th minute, that is, M+k \lt 300.
- The total penalty should be \leq 1000, that is, P+20\cdot k + (M+K) \leq 1000.
If both conditions are satisfied, it’s possible to make exactly k wrong submissions.
Otherwise, it isn’t.
Simply loop over all k starting from 0 to find the largest valid one.
You can stop at 300 since making more than 300 wrong submissions definitely won’t allow us to make the correct submission in time.
TIME COMPLEXITY:
\mathcal{O}(300) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
m, p = map(int, input().split())
ans = 0
for k in range(300):
if m+k < 300 and p + 20*k + (m+k) <= 1000: ans = k
print(ans)