PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
You have integers A, B, C.
You can do the following:
- Subtract 1 from A and 2 from B.
- Subtract 1 from B and 3 from C.
Is it possible to make all three values equal to 0?
EXPLANATION:
The only possible way we can affect A is by performing a type 1 operation.
Each such operation reduces A by 1, so we need A operations to make the first variable 0.
Note that this will reduce B by 2A.
Similarly, the only way we can change C is by performing a type 2 operation.
This will reduce C by 3 repeatedly.
So,
- If C is not a multiple of 3, it’s impossible to make it reach 0.
- Otherwise, we need \frac{C}{3} type 3 operations to make C equal to 0.
In this case, B will reduce by \frac{C}{3}.
After performing the forced operations that make A and C zero, no more operations can be performed - so B must already equal 0 as well.
B has reduced by both 2A and \frac{C}{3}, so it will equal 0 only if equals the sum of these two values.
Hence, we obtain the following:
- If C is not a multiple of 3, no solution exists.
- Otherwise, the answer is
Yesif and only if
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
for _ in range(int(input())):
a, b, c = map(int, input().split())
print('Yes' if c%3 == 0 and b == 2*a + (c//3) else 'No')