PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: iceknight1093
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Alice and Bob played a game.
You know that in the end, Alice’s had X more points than Bob; and their total number of points equaled Y.
Find Alice’s and Bob’s scores.
EXPLANATION:
This problem can be solved with some basic algebra.
Let’s use A to denote the number of points Alice had and B to denote the points Bob had.
Then, we know the following pieces of information:
- Alice had X points more than Bob.
This means A = B+X. - Their total points equaled Y.
This means A+B = Y
Putting the first equation into the second one, we obtain:
Y = A+B = (B+X)+B = 2B+X
Thus,
B = \frac{Y-X}{2}
This uniquely gives us the value of B.
Once B is known, A can be computed as just B+X; and it can be seen to equal \frac{Y+X}{2}.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
for _ in range(int(input())):
x, y = map(int, input().split())
print((y-x)//2 + x, (y-x)//2)