A - 二人の水筒

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

配点 : 166 点

問題文

高橋君と青木君は遠足に行きます。高橋君の水筒には A ミリリットル、青木君の水筒には B ミリリットルの水が入っています。

遠足では二人合わせて C ミリリットル以上の水が必要です。二人の水筒の水を合わせると必要な量に足りるなら Yes を、足りないなら No を出力してください。

制約

  • 1 \leq A \leq 10000
  • 1 \leq B \leq 10000
  • 1 \leq C \leq 20000
  • 入力はすべて整数

入力

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

A B C
  • 1 行目には、高橋君の水の量 A 、青木君の水の量 B 、必要な水の量 C がスペース区切りで与えられる。

出力

足りるなら Yes を、足りないなら No を 1 行で出力せよ。


入力例 1

600 300 700

出力例 1

Yes

入力例 2

200 200 500

出力例 2

No

入力例 3

1000 1 1000

出力例 3

Yes

入力例 4

5973 6341 712

出力例 4

Yes

入力例 5

8969 5381 18476

出力例 5

No

Score : 166 pts

Problem Statement

Takahashi and Aoki are going on a field trip. Takahashi's water bottle contains A milliliters of water, and Aoki's water bottle contains B milliliters of water.

On the trip, they need a total of at least C milliliters of water. If the water in their two bottles combined is enough to meet the required amount, print Yes; otherwise, print No.

Constraints

  • 1 \leq A \leq 10000
  • 1 \leq B \leq 10000
  • 1 \leq C \leq 20000
  • All input values are integers.

Input

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

A B C
  • The first line contains Takahashi's amount of water A, Aoki's amount of water B, and the required amount of water C, separated by spaces.

Output

Print Yes if there is enough water, and No otherwise, on a single line.


Sample Input 1

600 300 700

Sample Output 1

Yes

Sample Input 2

200 200 500

Sample Output 2

No

Sample Input 3

1000 1 1000

Sample Output 3

Yes

Sample Input 4

5973 6341 712

Sample Output 4

Yes

Sample Input 5

8969 5381 18476

Sample Output 5

No
B - 手記の縦読み

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

配点 : 233 点

問題文

高橋君は縦 H 行、横 W 列のマス目に英小文字を 1 文字ずつ書いた手記を持っています。手記の内容は H 個の文字列 S_1, S_2, \ldots, S_H で表され、 S_i の j 文字目は上から i 行目、左から j 列目のマスに書かれた文字です。

この手記には秘密のメッセージが隠されており、左から K 列目の文字を上から下へ順に読むと現れます。秘密のメッセージを出力してください。

制約

  • 1 \leq H \leq 10
  • 1 \leq W \leq 10
  • 1 \leq K \leq W
  • S_i は英小文字のみからなる長さ W の文字列
  • H 、 W 、 K は整数

入力

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

H W K
S_1
S_2
\vdots
S_H
  • 1 行目には、手記の行数 H 、列数 W 、読む列 K がスペース区切りで与えられる。
  • 2 行目から H 行にわたり、 1 + i 行目には上から i 行目の内容を表す文字列 S_i が与えられる。

出力

秘密のメッセージ(長さ H の文字列)を 1 行で出力せよ。


入力例 1

2 2 1
ab
ba

出力例 1

ab

入力例 2

3 3 2
abc
bde
cef

出力例 2

bde

入力例 3

1 1 1
z

出力例 3

z

入力例 4

2 2 2
ab
ba

出力例 4

ba

入力例 5

3 3 3
abc
bde
cef

出力例 5

cef

Score : 233 pts

Problem Statement

Takahashi has a memoir in which he wrote one lowercase English letter in each cell of a grid with H rows and W columns. The contents of the memoir are represented by H strings S_1, S_2, \ldots, S_H, where the j-th character of S_i is the letter written in the cell at the i-th row from the top and the j-th column from the left.

A secret message is hidden in this memoir, which appears when the characters in the K-th column from the left are read from top to bottom. Print the secret message.

Constraints

  • 1 \leq H \leq 10
  • 1 \leq W \leq 10
  • 1 \leq K \leq W
  • S_i is a string of length W consisting only of lowercase English letters
  • H, W, and K are integers

Input

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

H W K
S_1
S_2
\vdots
S_H
  • The first line contains the number of rows H, the number of columns W, and the column to read K, separated by spaces.
  • For each i from 1 to H, the (1+i)-th line contains the string S_i representing the contents of the i-th row from the top.

Output

Print the secret message (a string of length H) in one line.


Sample Input 1

2 2 1
ab
ba

Sample Output 1

ab

Sample Input 2

3 3 2
abc
bde
cef

Sample Output 2

bde

Sample Input 3

1 1 1
z

Sample Output 3

z

Sample Input 4

2 2 2
ab
ba

Sample Output 4

ba

Sample Input 5

3 3 3
abc
bde
cef

Sample Output 5

cef
C - 道路の凹みの補修

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

配点 : 333 点

問題文

高橋君は市の道路管理を担当しています。管理対象の道路は一直線に N 個の区画に分かれており、各区画には路面の高さが定められています。左から i 番目の区画の路面の高さは H_i です。

雨水がたまるのを防ぐため、高橋君は道路の凹んでいる箇所をアスファルトで補修したいと考えています。ここで、区画 i(2 \leq i \leq N - 1)が凹んでいるとは、その区画の路面の高さが左隣と右隣の両方の路面の高さよりも真に小さい状態、すなわち H_{i-1} > H_i かつ H_i < H_{i+1} が成り立つことを指します。両端の区画(区画 1 および区画 N)は凹んでいるとはみなしません。特に、N \leq 2 の場合は凹んでいる区画は存在しません。

高橋君は次の操作を 0 回以上繰り返し行うことができます。

  • 操作: N 個の区画のうち 1 つを選び、その区画の路面の高さを 1 だけ増やす。同じ区画を複数回選んでもよい。路面の高さを減らすことはできない。

なお、ある区画の路面の高さを上げた結果、別の区画が新たに凹みの条件を満たすようになる場合があることに注意してください。

すべての凹んでいる区画をなくすために必要な操作回数の最小値を求めてください。すなわち、どの区画 i(2 \leq i \leq N - 1)についても H_{i-1} > H_i かつ H_i < H_{i+1} が成り立たないようにするための最小操作回数を求めてください。

制約

  • 1 \leq N \leq 10^6
  • 1 \leq H_i \leq 10^9
  • 入力はすべて整数である。

入力

N
H_1 H_2 \ldots H_N
  • 1 行目には、区画の数を表す整数 N が与えられる。
  • 2 行目には、各区画の路面の高さを表す N 個の整数 H_1, H_2, \ldots, H_N がスペース区切りで与えられる。

出力

すべての凹みをなくすために必要な最小の操作回数を 1 行で出力せよ。


入力例 1

5
3 1 4 2 5

出力例 1

4

入力例 2

4
1 2 3 4

出力例 2

0

入力例 3

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

出力例 3

13

入力例 4

40
100 60 80 20 90 90 10 70 30 110 50 120 120 40 130 20 140 60 60 150 30 160 70 170 170 50 180 40 190 80 200 90 90 210 10 220 100 230 60 240

出力例 4

1500

入力例 5

1
1000000000

出力例 5

0

Score : 333 pts

Problem Statement

Takahashi is in charge of road maintenance for the city. The road under his management is divided into N sections in a straight line, and each section has a specified road surface height. The height of the i-th section from the left is H_i.

To prevent rainwater from pooling, Takahashi wants to repair the depressed parts of the road with asphalt. Here, section i (2 \leq i \leq N - 1) is said to be depressed if the height of its road surface is strictly smaller than the heights of both its left and right neighbors, i.e., H_{i-1} > H_i and H_i < H_{i+1} hold. The sections at both ends (section 1 and section N) are never considered depressed. In particular, if N \leq 2, there are no depressed sections.

Takahashi can perform the following operation zero or more times:

  • Operation: Choose one of the N sections and increase its road surface height by 1. The same section can be chosen multiple times. The road surface height cannot be decreased.

Note that increasing the height of a section may cause another section to newly satisfy the condition of being depressed.

Find the minimum number of operations required to eliminate all depressed sections. That is, find the minimum number of operations to ensure that for every section i (2 \leq i \leq N - 1), the condition H_{i-1} > H_i and H_i < H_{i+1} does not hold.

Constraints

  • 1 \leq N \leq 10^6
  • 1 \leq H_i \leq 10^9
  • All input values are integers.

Input

N
H_1 H_2 \ldots H_N
  • The first line contains an integer N, representing the number of sections.
  • The second line contains N space-separated integers H_1, H_2, \ldots, H_N, representing the road surface heights of the sections.

Output

Print the minimum number of operations required to eliminate all depressions in a single line.


Sample Input 1

5
3 1 4 2 5

Sample Output 1

4

Sample Input 2

4
1 2 3 4

Sample Output 2

0

Sample Input 3

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

Sample Output 3

13

Sample Input 4

40
100 60 80 20 90 90 10 70 30 110 50 120 120 40 130 20 140 60 60 150 30 160 70 170 170 50 180 40 190 80 200 90 90 210 10 220 100 230 60 240

Sample Output 4

1500

Sample Input 5

1
1000000000

Sample Output 5

0
D - 荷物の運搬

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

配点 : 400 点

問題文

高橋君は、1 から N までの番号がつけられた N 個の荷物を、最大 K 台のトラックを使って運ぼうとしています。荷物 i の重さは A_i です。

荷物 1, 2, \dots, N はこの順に一列に並んでおり、高橋君はこれらを並び順を保ったまま K 個以下の空でない連続する区間に分割し、区間ごとに 1 台のトラックに積んで運ぶことにしました。すべての荷物はちょうど 1 台のトラックに積まれます。

荷物を適切にトラックへ積み込んだとき、1 台のトラックに積まれる荷物の重さの合計の最大値として考えられる最小値を求めてください。

制約

  • 1 \leq K \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 入力に含まれる値はすべて整数

入力

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

N K
A_1
A_2
\vdots
A_N

出力

1 台のトラックに積まれる荷物の重さの合計の最大値として考えられる最小値を 1 行で出力してください。


入力例 1

5 3
1
2
3
4
5

出力例 1

6

入力例 2

4 2
10
20
30
40

出力例 2

60

入力例 3

10 4
15
23
8
37
12
9
45
18
22
31

出力例 3

63

入力例 4

25 7
45000000
120000000
89000000
230000000
67000000
150000000
310000000
78000000
420000000
190000000
88000000
260000000
530000000
140000000
95000000
370000000
610000000
280000000
170000000
490000000
330000000
820000000
210000000
560000000
130000000

出力例 4

1135000000

入力例 5

1 1
1000000000

出力例 5

1000000000

Score : 400 pts

Problem Statement

Takahashi is trying to transport N packages, numbered 1 to N, using at most K trucks. The weight of package i is A_i.

Packages 1, 2, \dots, N are arranged in a row in this order. Takahashi has decided to divide them into at most K non-empty contiguous segments while preserving their order, and load each segment onto 1 truck to transport them. Every package is loaded onto exactly 1 truck.

When the packages are appropriately loaded onto the trucks, find the minimum possible value of the maximum total weight of packages loaded onto 1 truck.

Constraints

  • 1 \leq K \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers.

Input

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

N K
A_1
A_2
\vdots
A_N

Output

Print the minimum possible value of the maximum total weight of packages loaded onto 1 truck in 1 line.


Sample Input 1

5 3
1
2
3
4
5

Sample Output 1

6

Sample Input 2

4 2
10
20
30
40

Sample Output 2

60

Sample Input 3

10 4
15
23
8
37
12
9
45
18
22
31

Sample Output 3

63

Sample Input 4

25 7
45000000
120000000
89000000
230000000
67000000
150000000
310000000
78000000
420000000
190000000
88000000
260000000
530000000
140000000
95000000
370000000
610000000
280000000
170000000
490000000
330000000
820000000
210000000
560000000
130000000

Sample Output 4

1135000000

Sample Input 5

1 1
1000000000

Sample Output 5

1000000000
E - 街灯の照らす範囲

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

配点 : 433 点

問題文

高橋君は、一直線上に並んだ N 個の街灯を管理しています。街灯には左から順に 1 から N までの番号が付いています。

各街灯は「点灯している」か「消灯している」かのいずれかの状態を持ちます。初期状態は文字列 S で与えられ、 S の i 文字目が 1 のとき、街灯 i が点灯していることを表します。

高橋君は Q 個の操作を順に処理します。操作は次の 2 種類です。

  • 1 x : 街灯 x の状態を反転する。つまり、消灯していれば点灯し、点灯していれば消灯する。
  • 2 d : 現在点灯している街灯から番号の差が d 以下であるすべての街灯を「照らされている街灯」としたとき、照らされている街灯の個数を求める。

操作 2 では、複数の点灯中の街灯から同時に照らされている街灯も 1 個として数えます。また、この操作によって街灯の状態は変化しません。

現在点灯している街灯が 1 つもない場合、操作 2 の答えは 0 です。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 10^5
  • S は 0 と 1 からなる長さ N の文字列
  • t_k \in \{1, 2\}
  • t_k = 1 のとき、1 \leq v_k \leq N
  • t_k = 2 のとき、0 \leq v_k \leq N
  • N, Q, t_k, v_k はすべて整数

入力

N Q
S
t_1 v_1
t_2 v_2
:
t_Q v_Q
  • 1 行目には、街灯の個数を表す N と、操作の個数を表す Q がスペース区切りで与えられる。
  • 2 行目には、長さ N の文字列 S が与えられる。
  • S の i 文字目が 1 のとき、街灯 i が点灯していることを表す。
  • S の i 文字目が 0 のとき、街灯 i が消灯していることを表す。
  • 続く Q 行のうち k 行目には、 k 番目の操作を表す t_k と v_k がスペース区切りで与えられる。
  • t_k = 1 のとき、 v_k は状態を反転する街灯の番号 x を表す。
  • t_k = 2 のとき、 v_k は照らされる範囲を判定する距離 d を表す。

出力

操作 2 が現れるたびに、その答えを 1 行に出力してください。


入力例 1

5 6
01010
2 0
2 1
1 3
2 0
1 2
2 1

出力例 1

2
5
3
4

入力例 2

4 8
0000
2 2
1 1
2 0
2 3
1 1
2 4
1 4
2 0

出力例 2

0
1
4
0
1

入力例 3

20 15
10010001000010000101
2 0
2 2
1 10
2 1
1 4
2 3
1 20
1 1
2 5
1 15
2 0
2 10
1 8
2 4
2 20

出力例 3

6
20
17
20
18
5
20
15
20

入力例 4

60 30
100000000101010101010000010000111000111000000000001001001001
2 0
2 1
2 5
1 30
1 31
2 0
2 2
1 1
1 60
2 10
1 45
2 3
1 22
1 23
1 24
2 4
2 60
1 10
2 0
1 10
2 1
1 50
1 51
1 52
2 6
1 31
2 2
1 5
2 15
2 30

出力例 4

18
39
59
18
48
60
54
55
60
19
42
57
51
60
60

入力例 5

1 5
0
2 0
2 1
1 1
2 0
2 1

出力例 5

0
0
1
1

Score : 433 pts

Problem Statement

Takahashi manages N street lights arranged in a straight line. The street lights are numbered from 1 to N from left to right.

Each street light is in one of two states: "on" or "off". The initial state is given by a string S, where if the i-th character of S is 1, it means street light i is on.

Takahashi processes Q operations in order. There are two types of operations:

  • 1 x : Toggle the state of street light x. That is, if it is off, turn it on; if it is on, turn it off.
  • 2 d : Considering all street lights whose number differs by at most d from any currently lit street light as "illuminated street lights", find the number of illuminated street lights.

In operation 2, a street light that is simultaneously illuminated by multiple lit street lights is still counted as 1. Also, this operation does not change the state of any street light.

If there are no currently lit street lights, the answer to operation 2 is 0.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 10^5
  • S is a string of length N consisting of 0 and 1
  • t_k \in \{1, 2\}
  • If t_k = 1, then 1 \leq v_k \leq N
  • If t_k = 2, then 0 \leq v_k \leq N
  • N, Q, t_k, v_k are all integers

Input

N Q
S
t_1 v_1
t_2 v_2
:
t_Q v_Q
  • The first line contains N, the number of street lights, and Q, the number of operations, separated by a space.
  • The second line contains a string S of length N.
  • If the i-th character of S is 1, street light i is on.
  • If the i-th character of S is 0, street light i is off.
  • The following Q lines each contain t_k and v_k separated by a space, representing the k-th operation.
  • If t_k = 1, v_k represents the number x of the street light whose state is toggled.
  • If t_k = 2, v_k represents the distance d used to determine the illumination range.

Output

For each operation 2, output the answer on a single line.


Sample Input 1

5 6
01010
2 0
2 1
1 3
2 0
1 2
2 1

Sample Output 1

2
5
3
4

Sample Input 2

4 8
0000
2 2
1 1
2 0
2 3
1 1
2 4
1 4
2 0

Sample Output 2

0
1
4
0
1

Sample Input 3

20 15
10010001000010000101
2 0
2 2
1 10
2 1
1 4
2 3
1 20
1 1
2 5
1 15
2 0
2 10
1 8
2 4
2 20

Sample Output 3

6
20
17
20
18
5
20
15
20

Sample Input 4

60 30
100000000101010101010000010000111000111000000000001001001001
2 0
2 1
2 5
1 30
1 31
2 0
2 2
1 1
1 60
2 10
1 45
2 3
1 22
1 23
1 24
2 4
2 60
1 10
2 0
1 10
2 1
1 50
1 51
1 52
2 6
1 31
2 2
1 5
2 15
2 30

Sample Output 4

18
39
59
18
48
60
54
55
60
19
42
57
51
60
60

Sample Input 5

1 5
0
2 0
2 1
1 1
2 0
2 1

Sample Output 5

0
0
1
1