P13959 [ICPC 2023 Nanjing R] Counter

Description

There is a counter with two buttons. Pressing the ``+`` button will increase the value on the counter by $1$ and pressing the ``c`` button will set the value on the counter to $0$. The initial value on the counter is $0$. Someone has performed $n$ operations on the counter. Each operation is to press one of the two buttons. There are $m$ known conditions where the $i$-th condition can be described as two integers $a_i$ and $b_i$, indicating that after the $a_i$-th operation the value on the counter is $b_i$. 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 $T$ indicating the number of test cases. For each test case: The first line contains two integers $n$ and $m$ ($1 \le n \le 10^9$, $1 \le m \le 10^5$) indicating the number of operations and the number of known conditions. For the following $m$ lines, the $i$-th line contains two integers $a_i$ and $b_i$ ($1 \le a_i \le n$, $0 \le b_i \le 10^9$) indicating that after the $a_i$-th operation the value on the counter is $b_i$. It's guaranteed that the sum of $m$ of all test cases will not exceed $5 \times 10^5$.

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 $\texttt{Yes}$. Otherwise output $\texttt{No}$.

Explanation/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 $8$ ways to press the buttons $3$ 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 $3$ times can only make the value on the counter at most $3$. It can't be $100$.