PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: pols_agyi_pols
Tester: kingmessi
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
You have a rectangle with dimensions A\times B, and a square with side length X.
In one move, you can change any one dimension of the rectangle to any positive number.
Find the minimum number of moves to make the square’s area be not less than the rectangle’s.
EXPLANATION:
The area of the rectangle is A\cdot B, and that of the square is X^2.
So, if A\cdot B \leq X^2 initially, no moves are needed.
Otherwise, notice that it’s always possible within two moves by setting A = B = 1, so we only need to decide whether using one move is enough.
Since we’re aiming to minimize the area of the rectangle, ideally we should set one of the dimensions to be 1.
If we set A = 1 the area will be B, and if we set B = 1 the area will be A instead.
If either of these values are \leq X^2, one move is enough; otherwise we’ll need 2.
So,
- If A\cdot B \leq X^2, the answer is 0.
- Otherwise, if \min(A, B) \leq X^2, the answer is 1.
- Otherwise, the answer is 2.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
a, b, x = map(int, input().split())
if a*b <= x*x: print(0)
elif min(a, b) <= x*x: print(1)
else: print(2)