QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB

#23921. 分數

Statistics

給定長度為 $N$ 嘅整數序列 $A = (A_1, A_2, \dots, A_N)$ 同埋長度為 $M$ 嘅整數序列 $B = (B_1, B_2, \dots, B_M)$。

你會用呢啲序列玩一個遊戲。最初,呢個遊戲嘅分數係 $0$。

呢個遊戲總共進行 $N$ 個回合。第 $i$ 個回合($1 \le i \le N$)按以下方式進行:

  1. 將目前分數加上 $A_i$。
  2. 如果加完之後嘅分數同 $B_1, B_2, \dots, B_M$ 入面嘅任何一個相等,就將分數變成 $0$。

請輸出最後一個回合結束時呢個遊戲嘅分數。

約束條件

  • $1 \le N \le 100$。
  • $1 \le M \le 100$。
  • $1 \le A_i \le 10$($1 \le i \le N$)。
  • $1 \le B_j \le 1000$($1 \le j \le M$)。
  • $B_j \ne B_k$($1 \le j < k \le M$)。
  • 輸入嘅所有數值都係整數。

輸入

輸入按以下格式由標準輸入給出:

N
A_1 A_2 ... A_N
M
B_1 B_2 ... B_M

輸出

輸出最後一個回合結束時呢個遊戲嘅分數。

範例

輸入 1

4
3 1 4 1
4
2 7 1 8

輸出 1

0

說明

  • 最初,呢個遊戲嘅分數係 $0$。
  • 喺第 $1$ 個回合,分數加上 $3$。加完之後嘅分數 $3$ 同 $B_1 = 2, B_2 = 7, B_3 = 1, B_4 = 8$ 全部唔同,所以呢個回合結束時嘅分數係 $3$。
  • 喺第 $2$ 個回合,分數加上 $1$。加完之後嘅分數 $4$ 同 $B_1, B_2, B_3, B_4$ 全部唔同,所以呢個回合結束時嘅分數係 $4$。
  • 喺第 $3$ 個回合,分數加上 $4$。加完之後嘅分數 $8$ 同 $B_4$ 相等,所以呢個回合結束時嘅分數係 $0$。
  • 喺第 $4$ 個回合,分數加上 $1$。加完之後嘅分數 $1$ 同 $B_3$ 相等,所以呢個回合結束時嘅分數係 $0$。
  • 最後一個回合結束時呢個遊戲嘅分數係 $0$,所以輸出 $0$。

輸入 2

5
1 4 1 4 2
3
1 3 5

輸出 2

6

說明

  • 最初,呢個遊戲嘅分數係 $0$。
  • 喺第 $1$ 個回合,分數加上 $1$。加完之後嘅分數 $1$ 同 $B_1$ 相等,所以呢個回合結束時嘅分數係 $0$。
  • 喺第 $2$ 個回合,分數加上 $4$。加完之後嘅分數 $4$ 同 $B_1 = 1, B_2 = 3, B_3 = 5$ 全部唔同,所以呢個回合結束時嘅分數係 $4$。
  • 喺第 $3$ 個回合,分數加上 $1$。加完之後嘅分數 $5$ 同 $B_3$ 相等,所以呢個回合結束時嘅分數係 $0$。
  • 喺第 $4$ 個回合,分數加上 $4$。加完之後嘅分數 $4$ 同 $B_1, B_2, B_3$ 全部唔同,所以呢個回合結束時嘅分數係 $4$。
  • 喺第 $5$ 個回合,分數加上 $2$。加完之後嘅分數 $6$ 同 $B_1, B_2, B_3$ 全部唔同,所以呢個回合結束時嘅分數係 $6$。
  • 最後一個回合結束時呢個遊戲嘅分數係 $6$,所以輸出 $6$。

輸入 3

2
10 10
3
1 11 111

輸出 3

20

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.