問題一覧 > 通常問題

No.1055 Snail's Pace

レベル : / AI推定難易度 : 2425 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 9
作問者 : QCFium / テスター : 夕叢霧香(ゆうむらきりか)
お気に入りにしたユーザー ProblemId : 3417 / 自分の提出
問題文最終更新日: 2020-05-15 23:31:13
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 248 (順位表) の他の問題:

Problem Statement

There are $N$ squares arranged in a horizontal line.
$M$ pieces are placed on them, and the $i(1 \le i \le M)$-th piece is on the $A_i$-th square from the left.
No two pieces are on the same square.
From now on, $Q$ instructions will arrive in order.
The $i(1 \le i \le Q)$-th instruction says "move the $B_i$-th piece to the adjacent square on its left or right".
In doing so, a piece must not leave the $N$ squares, and multiple pieces must not be on the same square.
Is it possible to follow all the instructions?

Input

$N\ M$
$A_1\ A_2\ A_3\ \dots\ A_M$
$Q$
$B_1\ B_2\ B_3\ \dots\ B_Q$

$1 \le N \le 10 ^ 6$
$1 \le M \le \min(N, 2 \times 10 ^ 5)$
$1 \le Q \le 2 \times 10 ^ 5$
$1 \le A_1 \lt A_2 \lt A_3 \lt \dots \lt A_M \le N$
$1 \le B_i \le M(1 \le i \le Q)$
All inputs are integers.

Output

Print YES if it is possible, and NO if it is impossible. Print a newline at the end.

Sample

Sample 1
Input
5 3
1 3 5
3
1 2 1
Output
YES

For example, it is possible by moving right, right, left in order over the 3 queries.

Sample 2
Input
5 3
1 3 5
3
1 3 2
Output
NO

You get stuck at the 3rd query.

Sample 3
Input
3 3
1 2 3
1
2
Output
NO

Sample 4
Input
9 5
1 2 3 8 9
8
3 3 2 2 1 4 5 4
Output
YES

Sample 5
Input
9 5
1 2 3 8 9
9
3 3 3 2 2 1 4 5 4
Output
NO

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