PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: raysh07
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
There are two dishes: one with F_1 fat and P_1 protein, and another with F_2 fat and P_2 protein.
Which dish has a smaller difference between fat and protein?
EXPLANATION:
Let d_1 = |F_1 - P_1| be the difference between fat and protein for the first dish.
Similarly define d_2 = |F_2 - P_2| for the second dish.
Then,
- If d_1 \lt d_2, the answer is
"First"
. - If d_1 \gt d_2, the answer is
"Second"
. - If d_1 = d_2, the answer is
"Both"
.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
f1, p1, f2, p2 = map(int, input().split())
d1, d2 = abs(f1 - p1), abs(f2 - p2)
if d1 < d2: print('First')
elif d1 > d2: print('Second')
else: print('Both')