No.1055 Snail's Pace
タグ : / 解いたユーザー数 9
作問者 :
QCFium
/ テスター :
夕叢霧香(ゆうむらきりか)
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もしくは右上の雲マークをクリックしてアカウントを作成してください。