PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: pols_agyi_pols
Tester: kingmessi
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef is at point X. He has 2Y friends - one at each position in [X-Y, X+Y] except for X itself.
He can only visit friends within a range of Z, i.e. within [X-Z, X+Z].
How many friends can be visited?
EXPLANATION:
If Z \ge Y, then Chef will be able to visit all his friends.
In this case, the answer is the number of Chef’s friends - which is 2Y.
If Z \lt Y, then some of Chef’s friends are too far away to visit.
Chef can only visit the friends in range [X-Z, X+Z].
There’s one friend at each position in this range (other than X), so the count of friends who can be visited is 2Z.
Both cases can be combined into a single formula: the answer is simply
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
for _ in range(int(input())):
x, y, z = map(int, input().split())
print(2*min(y, z))