QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB

#23921. Score

统计

問題文

長さ N の整数列 A = (A1, A2, …, AN) と長さ M の整数列 B = (B1, B2, …, BM) が与えられる.

あなたはこれらの数列を用いてゲームを行う.最初,このゲームの点数は 0 である.

このゲームでは N 回のラウンドを行う.i 回目 (1 ≦ i ≦ N) のラウンドは以下のように進行する.

  1. 現在の点数に Ai を加算する.
  2. もし加算後の点数が B1, B2, …, BM のいずれかと等しい場合,点数を 0 にする.

最後のラウンドが終了した時点でのこのゲームの点数を出力せよ.

制約

  • 1 ≦ N ≦ 100.
  • 1 ≦ M ≦ 100.
  • 1 ≦ Ai≦ 10 (1 ≦ i ≦ N).
  • 1 ≦ Bj≦ 1000 (1 ≦ j ≦ M).
  • Bj≠ Bk (1 ≦ j < k ≦ M).
  • 入力される値はすべて整数である.

入力

入力は以下の形式で標準入力から与えられる.
N
A1 A2 … AN
M
B1 B2 … BM

出力

最後のラウンドが終了した時点でのこのゲームの点数を出力せよ.


入力例 1

4
3 1 4 1
4
2 7 1 8

出力例 1

0
  • 最初,このゲームの点数は 0 である.
  • 1 回目のラウンドでは点数に 3 が加算される.加算後の点数 3 は B1= 2, B2= 7, B3= 1, B4= 8 のいずれとも異なるため,このラウンド終了時の点数は 3 となる.
  • 2 回目のラウンドでは点数に 1 が加算される.加算後の点数 4 は B1, B2, B3, B4 のいずれとも異なるため,このラウンド終了時の点数は 4 となる.
  • 3 回目のラウンドでは点数に 4 が加算される.加算後の点数 8 は B4 と等しいため,このラウンド終了時の点数は 0 となる.
  • 4 回目のラウンドでは点数に 1 が加算される.加算後の点数 1 は B3 と等しいため,このラウンド終了時の点数は 0 となる.
  • 最後のラウンドが終了した時点でのこのゲームの点数は 0 であるため,0 を出力する.

入力例 2

5
1 4 1 4 2
3
1 3 5

出力例 2

6
  • 最初,このゲームの点数は 0 である.
  • 1 回目のラウンドでは点数に 1 が加算される.加算後の点数 1 は B1 と等しいため,このラウンド終了時の点数は 0 となる.
  • 2 回目のラウンドでは点数に 4 が加算される.加算後の点数 4 は B1= 1, B2= 3, B3= 5 のいずれとも異なるため,このラウンド終了時の点数は 4 となる.
  • 3 回目のラウンドでは点数に 1 が加算される.加算後の点数 5 は B3 と等しいため,このラウンド終了時の点数は 0 となる.
  • 4 回目のラウンドでは点数に 4 が加算される.加算後の点数 4 は B1, B2, B3 のいずれとも異なるため,このラウンド終了時の点数は 4 となる.
  • 5 回目のラウンドでは点数に 2 が加算される.加算後の点数 6 は B1, B2, B3 のいずれとも異なるため,このラウンド終了時の点数は 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.