A - New Generation ABC

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

AtCoder Beginner Contest は、今回で 214 回目の開催となりました。

今までの AtCoder Beginner Contest において、出題される問題数は次のように変化しました。

  • 1 回目から 125 回目までは 4
  • 126 回目から 211 回目までは 6
  • 212 回目から 214 回目までは 8

N 回目の AtCoder Beginner Contest において出題された問題数を求めてください。

制約

  • 1 \leq N \leq 214
  • 入力は全て整数である。

入力

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

N

出力

答えを出力せよ。


入力例 1

214

出力例 1

8

入力例 2

1

出力例 2

4

入力例 3

126

出力例 3

6

Score : 100 points

Problem Statement

This is the 214-th AtCoder Beginner Contest (ABC).

The ABCs so far have had the following number of problems.

  • The 1-st through 125-th ABCs had 4 problems each.
  • The 126-th through 211-th ABCs had 6 problems each.
  • The 212-th through 214-th ABCs have 8 problems each.

Find the number of problems in the N-th ABC.

Constraints

  • 1 \leq N \leq 214
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

214

Sample Output 1

8

Sample Input 2

1

Sample Output 2

4

Sample Input 3

126

Sample Output 3

6
B - Zero Sum Game

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

1 から N の番号が付けられた N 人の人がおり、この中で一対一の勝敗のつくゲームを何度か行いました。N 人は最初にそれぞれ持ち点として 0 を持っており、各ゲームでは勝者の持ち点が 1 増え、敗者の持ち点が 1 減ります(持ち点が負になることもあります)。最終的に人 i\ (1\leq i\leq N-1) の持ち点が A_i になったとき、人 N の持ち点を求めてください。なお、ゲームの進行によらず最終的な人 N の持ち点は一意に定まることが示せます。

制約

  • 2\leq N\leq 100
  • -100\leq A_i\leq 100
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_{N-1}

出力

答えを出力せよ。


入力例 1

4
1 -2 -1

出力例 1

2

最終的に人 1,2,3 の持ち点が 1,-2,-1 となるような進行として、例えば次のようなものが考えられます。

  • 最初、人 1,2,3,4 の持ち点はそれぞれ 0,0,0,0 である。
  • 12 が対戦して、人 1 が勝利する。4 人の持ち点はそれぞれ 1,-1,0,0 である。
  • 14 が対戦して、人 4 が勝利する。4 人の持ち点はそれぞれ 0,-1,0,1 である。
  • 12 が対戦して、人 1 が勝利する。4 人の持ち点はそれぞれ 1,-2,0,1 である。
  • 23 が対戦して、人 2 が勝利する。4 人の持ち点はそれぞれ 1,-1,-1,1 である。
  • 24 が対戦して、人 4 が勝利する。4 人の持ち点はそれぞれ 1,-2,-1,2 である。

この場合、人 4 の持ち点は 2 になります。ほかにも別の進行が考えられますが、どのような進行であっても人 4 の持ち点は 2 になります。


入力例 2

3
0 0

出力例 2

0

入力例 3

6
10 20 30 40 50

出力例 3

-150

Score: 100 points

Problem Statement

There are N people labeled 1 to N, who have played several one-on-one games without draws. Initially, each person started with 0 points. In each game, the winner's score increased by 1 and the loser's score decreased by 1 (scores can become negative). Determine the final score of person N if the final score of person i\ (1\leq i\leq N-1) is A_i. It can be shown that the final score of person N is uniquely determined regardless of the sequence of games.

Constraints

  • 2 \leq N \leq 100
  • -100 \leq A_i \leq 100
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_{N-1}

Output

Print the answer.


Sample Input 1

4
1 -2 -1

Sample Output 1

2

Here is one possible sequence of games where the final scores of persons 1, 2, 3 are 1, -2, -1, respectively.

  • Initially, persons 1, 2, 3, 4 have 0, 0, 0, 0 points, respectively.
  • Persons 1 and 2 play, and person 1 wins. The players now have 1, -1, 0, 0 point(s).
  • Persons 1 and 4 play, and person 4 wins. The players now have 0, -1, 0, 1 point(s).
  • Persons 1 and 2 play, and person 1 wins. The players now have 1, -2, 0, 1 point(s).
  • Persons 2 and 3 play, and person 2 wins. The players now have 1, -1, -1, 1 point(s).
  • Persons 2 and 4 play, and person 4 wins. The players now have 1, -2, -1, 2 point(s).

In this case, the final score of person 4 is 2. Other possible sequences of games exist, but the score of person 4 will always be 2 regardless of the progression.


Sample Input 2

3
0 0

Sample Output 2

0

Sample Input 3

6
10 20 30 40 50

Sample Output 3

-150
C - Ticket Counter

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

AtCoder Land の入り口には 1 つのチケット売り場があり、来園客はこのチケット売り場の前に一列に並んで順にチケットを購入します。 チケットの購入手続きには一人当たり A 秒かかり、列の先頭の人がチケットを購入し終わると、(存在すれば)次の人がすぐさま購入手続きを開始します。

現在チケット売り場に並んでいる人はおらず、今から N 人の人が順にチケットを買いに来ます。 具体的には、i 番目の人は今から T_i 秒後にチケット売り場を訪れ、既に列が存在すればその最後尾に並び、存在しなければすぐさま購入手続きを開始します。 ここで、T_1< T_2< \dots < T_N です。

i\ (1\leq i\leq N) について、i 番目の人がチケットを購入し終わるのは今から何秒後か求めてください。

制約

  • 1\leq N \leq 100
  • 0\leq T_1< T_2< \dots < T_N\leq 10^6
  • 1\leq A\leq 10^6
  • 入力は全て整数

入力

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

N A
T_1 T_2 \dots T_N

出力

N 行出力せよ。 i\ (1\leq i \leq N) 行目には、i 番目の人がチケットを購入し終わるのは今から何秒後かを整数として出力せよ。


入力例 1

3 4
0 2 10

出力例 1

4
8
14

時系列順に以下のように物事が進行します。

  • 0 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
  • 2 秒後:2 番目の人がチケット売り場を訪れ、1 番目の人の後ろに並ぶ。
  • 4 秒後:1 番目の人がチケットを購入し終え、2 番目の人が購入手続きを開始する。
  • 8 秒後:2 番目の人がチケットを購入し終える。
  • 10 秒後:3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
  • 14 秒後:3 番目の人がチケットを購入し終える。

入力例 2

3 3
1 4 7

出力例 2

4
7
10

時系列順に以下のように物事が進行します。

  • 1 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
  • 4 秒後:1 番目の人がチケットを購入し終えると同時に、2 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
  • 7 秒後:2 番目の人がチケットを購入し終えると同時に、3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
  • 10 秒後:3 番目の人がチケットを購入し終える。

入力例 3

10 50000
120190 165111 196897 456895 540000 552614 561627 743796 757613 991216

出力例 3

170190
220190
270190
506895
590000
640000
690000
793796
843796
1041216

Score : 200 points

Problem Statement

At the entrance of AtCoder Land, there is a single ticket booth where visitors line up to purchase tickets one by one. The purchasing process takes A seconds per person. Once the person at the front of the line finishes purchasing their ticket, the next person (if any) immediately starts their purchasing process.

Currently, there is no one in line at the ticket booth, and N people will come to buy tickets one after another. Specifically, the i-th person will arrive at the ticket booth T_i seconds from now. If there is already a line, they will join the end of it; if not, they will start the purchasing process immediately. Here, T_1 < T_2 < \dots < T_N.

For each i\ (1 \leq i \leq N), determine how many seconds from now the i-th person will finish purchasing their ticket.

Constraints

  • 1 \leq N \leq 100
  • 0 \leq T_1 < T_2 < \dots < T_N \leq 10^6
  • 1 \leq A \leq 10^6
  • All input values are integers.

Input

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

N A
T_1 T_2 \dots T_N

Output

Print N lines. The i-th line should contain the number of seconds from now that the i-th person will finish purchasing their ticket.


Sample Input 1

3 4
0 2 10

Sample Output 1

4
8
14

The events proceed in the following order:

  • At 0 seconds: The 1st person arrives at the ticket booth and starts the purchasing process.
  • At 2 seconds: The 2nd person arrives at the ticket booth and joins the line behind the 1st person.
  • At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person starts the purchasing process.
  • At 8 seconds: The 2nd person finishes purchasing their ticket.
  • At 10 seconds: The 3rd person arrives at the ticket booth and starts the purchasing process.
  • At 14 seconds: The 3rd person finishes purchasing their ticket.

Sample Input 2

3 3
1 4 7

Sample Output 2

4
7
10

The events proceed in the following order:

  • At 1 second: The 1st person arrives at the ticket booth and starts the purchasing process.
  • At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person arrives at the ticket booth and starts the purchasing process.
  • At 7 seconds: The 2nd person finishes purchasing their ticket, and the 3rd person arrives at the ticket booth and starts the purchasing process.
  • At 10 seconds: The 3rd person finishes purchasing their ticket.

Sample Input 3

10 50000
120190 165111 196897 456895 540000 552614 561627 743796 757613 991216

Sample Output 3

170190
220190
270190
506895
590000
640000
690000
793796
843796
1041216
D - 1D Pawn

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

N 個のマスが左右一列に並んでおり、左から順にマス 1、マス 2、…、マス N と番号づけられています。
また、K 個のコマがあり、最初左から i 番目のコマはマス A_i に置かれています。
これらに対して、Q 回の操作を行います。 i 回目の操作では次の操作を行います。

  • 左から L_i 番目のコマが一番右のマスにあるならば何も行わない。
  • そうでない時、左から L_i 番目のコマがあるマスの 1 つ右のマスにコマが無いならば、左から L_i 番目のコマを 1 つ右のマスに移動させる。 1 つ右のマスにコマがあるならば、何も行わない。

Q 回の操作が終了した後の状態について、i=1,2,\ldots,K に対して左から i 番目のコマがあるマスの番号を出力してください。

制約

  • 1\leq K\leq N\leq 200
  • 1\leq A_1<A_2<\cdots<A_K\leq N
  • 1\leq Q\leq 1000
  • 1\leq L_i\leq K
  • 入力はすべて整数

入力

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

N K Q
A_1 A_2 \ldots A_K
L_1 L_2 \ldots L_Q

出力

K 個の整数を空白区切りで一行に出力せよ。 ここで、i 個目の整数は、 Q 回の操作が終了した後の状態について、左から i 番目のコマの番号を表す。


入力例 1

5 3 5
1 3 4
3 3 1 1 2

出力例 1

2 4 5

最初、コマはマス 1, 3, 4 にあります。これに対して以下のように操作が行われます。

  • 左から 3 番目のコマはマス 4 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 3 番目のコマをマス 5 に動かします。 コマはマス 1, 3, 5 にある状態になります。
  • 左から 3 番目のコマはマス 5 にあります。 これは一番右のマスなので、何も行いません。 コマはマス 1, 3, 5 にある状態のままです。
  • 左から 1 番目のコマはマス 1 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 1 番目のコマをマス 2 に動かします。 コマはマス 2, 3, 5 にある状態になります。
  • 左から 1 番目のコマはマス 2 にあります。 これは一番右のマスでありませんが、その 1 つ右のマス(マス 3 )にコマが置かれているため、何も行いません。 コマはマス 2, 3, 5 にある状態のままです。
  • 左から 2 番目のコマはマス 3 にあります。 これは一番右のマスでなく、その右のマスにもコマが置かれていないため、左から 2 番目のコマをマス 4 に動かします。 コマはマス 2, 4, 5 にある状態になります。

よって、Q 回の操作が終わった後でコマはマス 2, 4, 5 に置かれているため、2,4,5 を空白区切りでこの順に出力します。


入力例 2

2 2 2
1 2
1 2

出力例 2

1 2

入力例 3

10 6 9
1 3 5 7 8 9
1 2 3 4 5 6 5 6 2

出力例 3

2 5 6 7 9 10

Score : 200 points

Problem Statement

There are N squares, indexed Square 1, Square 2, …, Square N, arranged in a row from left to right.
Also, there are K pieces. The i-th piece from the left is initially placed on Square A_i.
Now, we will perform Q operations against them. The i-th operation is as follows:

  • If the L_i-th piece from the left is on its rightmost square, do nothing.
  • Otherwise, move the L_i-th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.

Print the index of the square on which the i-th piece from the left is after the Q operations have ended, for each i=1,2,\ldots,K.

Constraints

  • 1\leq K\leq N\leq 200
  • 1\leq A_1<A_2<\cdots<A_K\leq N
  • 1\leq Q\leq 1000
  • 1\leq L_i\leq K
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K Q
A_1 A_2 \ldots A_K
L_1 L_2 \ldots L_Q

Output

Print K integers in one line, with spaces in between. The i-th of them should be the index of the square on which the i-th piece from the left is after the Q operations have ended.


Sample Input 1

5 3 5
1 3 4
3 3 1 1 2

Sample Output 1

2 4 5

At first, the pieces are on Squares 1, 3, and 4. The operations are performed against them as follows:

  • The 3-rd piece from the left is on Square 4. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 3-rd piece from the left to Square 5. Now, the pieces are on Squares 1, 3, and 5.
  • The 3-rd piece from the left is on Square 5. This is the rightmost square, so do nothing. The pieces are still on Squares 1, 3, and 5.
  • The 1-st piece from the left is on Square 1. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 1-st piece from the left to Square 2. Now, the pieces are on Squares 2, 3, and 5.
  • The 1-st piece from the left is on Square 2. This is not the rightmost square, but the next square on the right (Square 3) contains a piece, so do nothing. The pieces are still on Squares 2, 3, and 5.
  • The 2-nd piece from the left is on Square 3. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 2-nd piece from the left to Square 4; Now, the pieces are still on Squares 2, 4, and 5.

Thus, after the Q operations have ended, the pieces are on Squares 2, 4, and 5, so 2, 4, and 5 should be printed in this order, with spaces in between.


Sample Input 2

2 2 2
1 2
1 2

Sample Output 2

1 2

Sample Input 3

10 6 9
1 3 5 7 8 9
1 2 3 4 5 6 5 6 2

Sample Output 3

2 5 6 7 9 10
E - Festival

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

AtCoder 王国では、これから N 日間のお祭りが開催されます。そのうち、A_1 日目、A_2 日目、\dotsA_M 日目の M 日では花火が上がります。ここで、お祭りの最終日には花火が上がることが保証されます。(つまり、A_M=N が保証されます。)

i=1,2,\dots,N に対して、以下の問題を解いてください。

  • i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後か?ただし、i 日目に花火が上がる場合 0 日後とする。

制約

  • 1 \le M \le N \le 2 \times 10^5
  • 1 \le A_1 < A_2 < \dots < A_M = N
  • 入力は全て整数

入力

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

N M
A_1 A_2 \dots A_M

出力

N 行出力せよ。

i(1 \le i \le N) 行目には、i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後かを整数として出力せよ。


入力例 1

3 2
2 3

出力例 1

1
0
0

AtCoder 王国ではお祭りを 3 日間開催し、2,3 日目に花火が上がります。

  • 1 日目以降で初めて花火が上がるのは 2 日目なので、1 日目から数えて 1 日後です。
  • 2 日目以降で初めて花火が上がるのは 2 日目なので、2 日目から数えて 0 日後です。
  • 3 日目以降で初めて花火が上がるのは 3 日目なので、3 日目から数えて 0 日後です。

入力例 2

8 5
1 3 4 7 8

出力例 2

0
1
0
0
2
1
0
0

Score : 250 points

Problem Statement

The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1-th, A_2-th, \dots, A_M-th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.)

For each i=1,2,\dots,N, solve the following problem.

  • How many days later from the i-th day will fireworks be launched for the first time on or after the i-th day? If fireworks are launched on the i-th day, it is considered to be 0 days later.

Constraints

  • 1 \le M \le N \le 2 \times 10^5
  • 1 \le A_1 < A_2 < \dots < A_M = N
  • All input values are integers.

Input

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

N M
A_1 A_2 \dots A_M

Output

Print N lines.

The i-th line (1 \le i \le N) should contain an integer representing the number of days from the i-th day until fireworks are launched for the first time on or after the i-th day.


Sample Input 1

3 2
2 3

Sample Output 1

1
0
0

The kingdom holds a festival for 3 days, and fireworks are launched on the 2-nd and 3-rd days.

  • From the 1-st day, the first time fireworks are launched is the 2-nd day of the festival, which is 1 day later.
  • From the 2-nd day, the first time fireworks are launched is the 2-nd day of the festival, which is 0 days later.
  • From the 3-rd day, the first time fireworks are launched is the 3-rd day of the festival, which is 0 days later.

Sample Input 2

8 5
1 3 4 7 8

Sample Output 2

0
1
0
0
2
1
0
0