B - Robot Weight Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

ロボットがあり、はじめロボットの重さは X です。 このロボットには、同時に取り付けられる部品が種類 1, 種類 2,\ldots, 種類 NN 種類あります。 種類 i\ (1\le i\le N) の部品の重さは W _ i です。 はじめ、ロボットには N 種類のうちのどの部品もついていません。

次の Q 個のクエリを順に処理してください。 i 番目 (1\le i\le Q) のクエリは、整数 P _ i で表される次のようなクエリです。

  • 現在、ロボットに種類 P _ i の部品がついていない場合は取り付け、ついている場合は取り外す。その後、現在のロボットの重さを出力する。

制約

  • 1\le X\le100
  • 1\le N\le100
  • 1\le W _ i\le100\ (1\le i\le N)
  • 1\le Q\le100
  • 1\le P _ i\le N\ (1\le i\le Q)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

X
N
W _ 1 W _ 2 \ldots W _ N
Q
P _ 1
P _ 2
\vdots
P _ Q

出力

Q 行にわたって出力せよ。 i 行目 (1\le i\le Q) には、i 番目のクエリを処理した結果を出力せよ。


入力例 1

31
4
15 92 65 35
4
3
1
4
1

出力例 1

96
111
146
131

はじめ、ロボットの重さは 31 です。 それぞれのクエリで、ロボットの重さは次のようになります。

  • 1 番目のクエリでは、種類 3 のパーツをロボットに取り付ける。ロボットの重さは 31+65=96 になる。
  • 2 番目のクエリでは、種類 1 のパーツをロボットに取り付ける。ロボットの重さは 96+15=111 になる。
  • 3 番目のクエリでは、種類 4 のパーツをロボットに取り付ける。ロボットの重さは 111+35=146 になる。
  • 4 番目のクエリでは、種類 1 のパーツをロボットから取り外す。ロボットの重さは 146-15=131 になる。

入力例 2

41
10
73 8 55 26 97 48 37 47 35 55
15
1
2
7
1
6
3
10
8
4
8
1
5
9
9
3

出力例 2

114
122
159
86
134
189
244
291
317
270
343
440
475
440
385

Score : 200 points

Problem Statement

There is a robot, and initially the weight of the robot is X. This robot has N types of parts that can be attached simultaneously: type 1, type 2,\ldots, type N. The weight of the type i\ (1\le i\le N) part is W _ i. Initially, none of the N types of parts are attached to the robot.

Process the following Q queries in order. The i-th query (1\le i\le Q) is represented by an integer P _ i and is as follows:

  • If the type P _ i part is not currently attached to the robot, attach it; if it is attached, remove it. Then, print the current weight of the robot.

Constraints

  • 1\le X\le100
  • 1\le N\le100
  • 1\le W _ i\le100\ (1\le i\le N)
  • 1\le Q\le100
  • 1\le P _ i\le N\ (1\le i\le Q)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

X
N
W _ 1 W _ 2 \ldots W _ N
Q
P _ 1
P _ 2
\vdots
P _ Q

Output

Output Q lines. The i-th line (1\le i\le Q) should contain the result of processing the i-th query.


Sample Input 1

31
4
15 92 65 35
4
3
1
4
1

Sample Output 1

96
111
146
131

Initially, the weight of the robot is 31. For each query, the weight of the robot becomes as follows:

  • In the 1-st query, attach the type 3 part to the robot. The weight of the robot becomes 31+65=96.
  • In the 2-nd query, attach the type 1 part to the robot. The weight of the robot becomes 96+15=111.
  • In the 3-rd query, attach the type 4 part to the robot. The weight of the robot becomes 111+35=146.
  • In the 4-th query, remove the type 1 part from the robot. The weight of the robot becomes 146-15=131.

Sample Input 2

41
10
73 8 55 26 97 48 37 47 35 55
15
1
2
7
1
6
3
10
8
4
8
1
5
9
9
3

Sample Output 2

114
122
159
86
134
189
244
291
317
270
343
440
475
440
385