#P13959. [ICPC 2023 Nanjing R] 计数器
[ICPC 2023 Nanjing R] 计数器
Description
There is a counter with two buttons. Pressing the + button will increase the value on the counter by and pressing the c button will set the value on the counter to . The initial value on the counter is .
Someone has performed operations on the counter. Each operation is to press one of the two buttons. There are known conditions where the -th condition can be described as two integers and , indicating that after the -th operation the value on the counter is .
Is there a way to press the buttons so that all known conditions are satisfied?
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and (, ) indicating the number of operations and the number of known conditions.
For the following lines, the -th line contains two integers and (, ) indicating that after the -th operation the value on the counter is .
It's guaranteed that the sum of of all test cases will not exceed .
Output Format
For each test case output one line. If there exists a way to press the buttons so that all known conditions are satisfied, output . Otherwise output .
3
7 4
4 0
2 2
7 1
5 1
3 2
2 2
3 1
3 1
3 100
Yes
No
No
Hint
For the first sample test case, pressing buttons in the order of ++cc+c+ can satisfy all known conditions.
For the second sample test case, there are ways to press the buttons times.
$$\begin{array}{|c|c|c|c|c|c|c|} \hline \textbf{Presses} & \textbf{$2$-nd Op. Result} & \textbf{$3$-rd Op. Result} & & \textbf{Presses} & \textbf{$2$-nd Op. Result} & \textbf{$3$-rd Op. Result} \\ \hline ccc & 0 & 0 & & +cc & 0 & 0 \\ \hline cc+ & 0 & 1 & & +c+ & 0 & 1 \\ \hline c+c & 1 & 0 & & ++c & 2 & 0 \\ \hline c++ & 1 & 2 & & +++ & 2 & 3 \\ \hline \end{array}$$There is no way to satisfy all known conditions.
For the third sample test case, pressing the buttons times can only make the value on the counter at most . It can't be .
京公网安备 11011102002149号