問題一覧 > 通常問題

No.3560 Giant Salamander

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 34
作問者 : TKTYI / テスター : 👑 みうね fluorine HoyHoyCharhang jastaway soryuusi0219 yaaya butsurizuki wasab1 tatesoto KumaTachiRen
お気に入りにしたユーザー ProblemId : 13377 / 自分の提出
問題文最終更新日: 2026-08-15 01:55:50
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
KCPC新歓杯2026 (順位表) の他の問題:

Problem Statement

There are $N$ cells arranged in a circle. The cells are numbered from $1$ to $N$ in clockwise order. Cell $i$ and cell $i+1 ( 1 \le i \le N-1 )$ are adjacent, and cell $N$ and cell $1$ are also adjacent.

Initially, each cell contains $1$ giant salamander. You may perform the following operation any number of times (possibly $0$).

  • Choose $2$ adjacent cells such that both cells contain at least $1$ giant salamander.
  • Choose one of these cells and move all giant salamanders in that cell to the other cell.

Output Yes if it is possible to reach a state where, when you finish performing operations, giant salamanders remain only in cells $A_1, A_2, \dots, A_M$ and cell $A_i$ contains $B_i$ giant salamanders; otherwise, output No.

You are given $T$ test cases; solve each of them.

Input

The input is given from Standard Input in the following format.

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$

Here, $\text{case}_i$ denotes the input for the $i$-th test case. Each test case is given in the following format.

$N$ $M$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_M$ $B_M$
  • $1 \le T \le 2 \times 10^5$
  • $3 \le N \le 10^9$
  • $1 \le M \le \min (N, 2 \times 10^5)$
  • $1 \le A_1 < A_2 < \dots < A_M \le N$
  • $1 \le B_i$
  • $\sum_{1 \le i \le M} B_i = N$
  • All input values are integers.
  • The sum of $M$ over all test cases is at most $2 \times 10^5$.

Partial Score

This problem has partial scoring based on subtasks.

SubtaskScoreConstraints
部分点15% (12 pts)$M=1$ または $M=N$
部分点220% (50 pts)$T \le 10, N \le 7$
部分点315% (37 pts)すべてのテストケースにおける $N$ の総和は $2 \times 10^3$ 以下である
部分点440% (100 pts)すべてのテストケースにおける $N$ の総和は $2 \times 10^5$ 以下である
満点20% (50 pts)追加の制約はない

Output

Output $T$ lines. On the $i$-th line, for the $i$-th test case, output Yes if the condition can be satisfied, and No otherwise.

Sample

Sample 1
Input
3
4 2
1 2
3 2
3 3
1 1
2 1
3 1
6 3
1 1
3 1
5 4
Output
Yes
Yes
No

For test case $1$, the condition can be satisfied, for example, by performing the following operations.

  • Choose cell $4$ and cell $1$, and move the giant salamanders in cell $4$ to cell $1$. Cell $1$ now contains $2$ giant salamanders.
  • Choose cell $2$ and cell $3$, and move the giant salamanders in cell $2$ to cell $3$. Cell $3$ now contains $2$ giant salamanders.

For test case $2$, the condition can be satisfied by performing no operations.

For test case $3$, it is impossible to perform operations so that the condition is satisfied.

This input satisfies the constraints of all subtasks except subtask $1$.

Sample 2
Input
2
1000000000 3
2025 999999998
2026 1
2027 1
1000000000 3
2025 999999997
2026 2
2027 1
Output
Yes
No

This input satisfies the constraints for the full score.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。