TELHOME - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: iceknight1093
Tester: iceknight1093
Editorialist: iceknight1093

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Find the minimum time needed to travel D kilometers, if you can teleport up to T kilometers at most once for no time cost, and otherwise walk one kilometer an hour.

EXPLANATION:

The teleport is free, so we might as well use it.

If D \le T then the teleport alone is enough to get us home, and the answer is 0.

If D \gt T, then the teleport shaves off at most T kilometers, and we have to walk the rest of the way.
It’s of course optimal to teleport exactly T kilometers, and that leaves D-T kilometers to walk.
At a rate of one kilometer per hour, that takes D-T hours to reach home.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
d, t = map(int, input().split())
if t >= d: print(0)
else: print(d-t)