問題一覧 > 通常問題

No.3750 Mischievous Resident (Easy)

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 44
作問者 : marc2825 / テスター : siganai
お気に入りにしたユーザー ProblemId : 13471 / 自分の提出
問題文最終更新日: 2026-10-24 23:51:25
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
yukicoder contest 516 (順位表) の他の問題:
Problem A and Problem E share the same setting, but ask for different things. In Problem A, you only need to determine whether the target arrangement is reachable.

Problem Statement

There are $M$ elevators in a building with $N$ floors. The elevators are numbered $1,2,\ldots,M$ and are distinguishable from one another.

Initially, elevator $i$ is stopped at floor $S_i$. Multiple elevators may be stopped at the same floor.

You can move around using the stairs and press the "call button" on each floor any number of times. When you press the button on floor $F$ $(1 \leq F \leq N)$, exactly $1$ elevator moves according to the following rules.

  • The elevator with the smallest distance $|x-F|$ from its current position $x$ to floor $F$ moves to floor $F$.
  • If there are multiple elevators with the smallest distance, you may freely choose $1$ of them to move.

You are given an integer sequence $G_1,G_2,\ldots,G_M$ representing the target arrangement of the elevators.

You are given $Q$ test cases. For each test case, determine whether it is possible, by pressing call buttons any number of times, to have elevator $i$ stopped at floor $G_i$ for all $i$.

Constraints

  • $1 \leq Q \leq 2 \times 10^5$
  • $1 \leq N \leq 10^9$
  • $1 \leq M \leq 2 \times 10^5$
  • $1 \leq S_i \leq N$
  • $1 \leq G_i \leq N$
  • The sum of $M$ over all test cases is at most $2 \times 10^5$
  • All input values are integers

Input

The input is given from standard input in the following format. Here, the $q\ (1 \leq q \leq Q)$-th test case is denoted by $\mathrm{case}_q$.

$Q$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_Q$

Each test case is given in the following format.

$N$ $M$
$S_1$ $S_2$ $\ldots$ $S_M$
$G_1$ $G_2$ $\ldots$ $G_M$

Here, $S_i$ denotes the initial position of elevator $i$, and $G_i$ denotes the target position of elevator $i$.

Output

Print $Q$ lines.
On the $q$-th line, print Yes if the target arrangement can be achieved for the $q$-th test case, and No otherwise.

Sample

Sample 1
Input
5
10 3
8 5 2
9 6 3
10 2
2 8
8 2
10 3
5 5 8
6 4 9
20 2
1 14
5 7
10 1
5
5
Output
Yes
No
Yes
Yes
Yes

In test case $1$, for example, pressing the buttons on floors $9$, $6$, and $3$ in this order moves each elevator to its target position.

In test case $2$, the target arrangement cannot be achieved no matter how you press the buttons. Note that the elevators are distinguishable from one another.

In test case $3$, for example, pressing the buttons on floors $9$, $4$, and $6$ in this order achieves the target arrangement.
Elevators $1$ and $2$ are both initially at floor $5$, but note that if there are multiple elevators with the smallest distance, you may freely choose which of them to move.

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