PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: wasd2401
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
Alice has A points and Bob has B points in a basketball game.
Alice wants to end up with at least 10 points more than Bob.
A single shot earns her either two or three points. What’s the minimum number of shots she needs?
EXPLANATION:
If A \geq B+10 already, the answer is 0: the condition is satisfied already, and no more shots are needed.
Otherwise, clearly it’s better for Alice to always shoot three-pointers.
The constraints are small enough that you can now simulate the process. That is, while A \lt B+10, add 3 to A and increment the answer by 1.
Alternatively, the problem can be solved mathematically: the answer is the difference between B+10 and A, divided by 3 and rounded up.
That is, \left\lceil \frac{B+10-A}{3} \right\rceil.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
a, b = map(int, input().split())
ans = 0
while a < b+10:
ans += 1
a += 3
print(ans)