Order Capital Round 1 (Codeforces Round 1038, Div. 1 + Div. 2)
A
Greedy Grid
Codeforces
800
原题
←B →
翻译中…

A path in a grid is called greedy if it starts at the top-left cell and moves only to the right or downward, always moving to its neighbor with the greater value (or either if the values are equal).

翻译中…

The value of a path is the sum of the values of the cells it visits, including the start and end.

翻译中…

Does there exist an $n \times m$ grid of nonnegative integers such that no greedy path achieves the maximum value among all down/right paths?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $n$, $m$ ($1 \leq n, m \leq 100$) — the number of rows and columns in the grid, respectively.

翻译中…

Output

翻译中…

For each test case, on a separate line output "YES" if the required grid exists, and "NO" otherwise.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

In the first test case, an example of a grid in which no greedy path achieves the maximum value out of all down/right paths is: $$ \begin{bmatrix} 3 & 5 & 1 \\ 2 & 1 & 2 \\ 5 & 4 & 3 \\ \end{bmatrix} $$ Let $a_{i, j}$ denote the value of the cell in the $i$-th row and $j$-th column. The maximum value of a down/right path is $a_{1,1} + a_{2,1} + a_{3,1} + a_{3,2} + a_{3,3} = 17$. This path isn't greedy because $a_{1,2}$ is greater than $a_{2,1}$; thus, a greedy path must move right in the first step. The maximum value of a greedy path is $a_{1,1} + a_{1,2} + a_{2,2} + a_{3,2} + a_{3,3} = 16$.

翻译中…

In the second test case, it can be proven that no grid satisfies the conditions.

翻译中…

样例

Input #1
2
3 3
1 2
Output #1
YES
NO
InputCopy OutputCopy
题目信息
题号
2122A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。