QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 1024 MB

#23921. 分数

Estadísticas

给定长度为 $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.