問題一覧 > 通常問題

No.2401 Dirty Shoes and Stairs

レベル : / AI推定難易度 : 162 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 211
作問者 : 👑 獅子座じゃない人 / テスター : 👑 amentorimaru
お気に入りにしたユーザー ProblemId : 9816 / 自分の提出
問題文最終更新日: 2023-08-03 22:02:20
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 400 (順位表) の他の問題:

Problem Statement

There is a staircase with $N$ steps. Rueru wants to climb the staircase from step $0$ to step $N$, then turn back and descend to step $0$.

Rueru climbs the stairs with $M_1$ landings. On the $1$st landing, he goes up $A_1$ steps and lands on step $A_1$; on the $2$nd landing, he goes up $A_2$ steps and lands on step $(A_1+A_2)$; $\dots$; on the $M_1$-th landing, he goes up $A_{M_1}$ steps and lands on step $\sum_{i=1}^{M_1} A_i$. It is guaranteed that $\sum_{i=1}^{M_1} A_i=N$.

When descending the stairs, he makes $M_2$ landings. On the $1$st landing, he goes down $B_1$ steps and lands on step $(N-B_1)$; on the $2$nd landing, he goes down $B_2$ steps and lands on step $(N-B_1-B_2)$; $ \ldots$; on the $M_2$-th landing, he goes down $B_{M_2}$ steps and lands on step $(N-\sum_{i=1}^{M_2} B_i)$. It is guaranteed that $\sum_{i=1}^{M_2} B_i=N$.

Rueru's shoes are dirty, so every step he lands on becomes dirty. Steps $0$ and $N$ are among the steps that get dirty.

Output the number of steps that are not dirty after Rueru has climbed up and come back down the stairs.

Input

$N$
$M_1$
$A_1\ A_2\ A_3\ \ldots\ A_{M_1}$
$M_2$
$B_1\ B_2\ B_3\ \ldots\ B_{M_2}$

  • All inputs are integers.
  • $1\leq N\leq 2\times 10^5$
  • $1\leq M_1\leq N$
  • $1\leq M_2\leq N$
  • $1\leq A_i\ (1\leq i\leq M_1)$
  • $1\leq B_i\ (1\leq i\leq M_2)$
  • $\sum_{i=1}^{M_1} A_i=N$
  • $\sum_{i=1}^{M_2} B_i=N$

Output

Output the number of steps that are not dirty, followed by a newline.

Sample

Sample 1
Input
4
2
2 2
3
1 1 2
Output
1

When climbing the stairs, Rueru lands on steps $2$ and $4$. When descending, he lands on steps $3$, $2$, and $0$.

After he has climbed up and come back down, the only step that is not dirty is step $1$, so output $1$.

Sample 2
Input
4
4
1 1 1 1
1
4
Output
0

Sample 3
Input
10
5
1 1 1 2 5
6
1 2 3 2 1 1
Output
2

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