PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: satyam_343
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef has N toys.
For M days, each day he will choose to play with one toy (if he still has one), and then break it.
How many toys will remain after M days?
EXPLANATION:
Chef plays with (and breaks) one toy every day.
Over M days, this means up to M toys will be broken.
So,
- If N \ge M, exactly M toys will break (one every day).
So, there will be (N - M) toys remaining. - If N \lt M, Chef will end up breaking all his toys before the M-th day.
So, there will be 0 toys remaining.
This can be checked using an if condition.
Alternately, note that the answer is either N-M or 0, whichever is larger.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
n, m = map(int, input().split())
print(max(0, n - m))