55 atcoder#ABC224B. [ABC224B] Mongeness
[ABC224B] Mongeness
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns, where each square contains an integer. The integer written on the square at the -th row from the top and -th column from the left is .
Determine whether the grid satisfies the condition below.
$A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$ holds for every quadruple of integers such that and .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the grid satisfies the condition in the Problem Statement, print Yes
; otherwise, print No
.
3 3
2 1 4
3 1 3
6 4 1
Yes
There are nine quadruples of integers such that and . For all of them, $A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$ holds. Some examples follow.
- For , we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 3 + 1 = A_{i_2, j_1} + A_{i_1, j_2}$.
- For , we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 3 \leq 3 + 4 = A_{i_2, j_1} + A_{i_1, j_2}$.
- For , we have $A_{i_1, j_1} + A_{i_2, j_2} = 1 + 3 \leq 1 + 4 = A_{i_2, j_1} + A_{i_1, j_2}$.
- For , we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 4 \leq 6 + 1 = A_{i_2, j_1} + A_{i_1, j_2}$.
- For , we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 6 + 4 = A_{i_2, j_1} + A_{i_1, j_2}$.
We can also see that the property holds for the other quadruples: $(i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3)$.
Thus, we should print Yes
.
2 4
4 3 2 1
5 6 7 8
No
We should print No
because the condition is not satisfied.
This is because, for example, we have $A_{i_1, j_1} + A_{i_2, j_2} = 4 + 8 > 5 + 1 = A_{i_2, j_1} + A_{i_1, j_2}$ for .