QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB

#23921. 分數

Statistiques

給定長度為 $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.