A - Service Tickets

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

高橋君の店に N 人の客が来店し、 i 番目の客は A_i 円を支払いました。

高橋君は、支払い額 100 円ごとにサービス券を 1 枚渡します。つまり、 A_i 円を支払った客には A_i を 100 で割った商(小数点以下切り捨て)の枚数だけ渡します。ただし、 1 人の客に渡す枚数は最大 M 枚です。

高橋君が渡したサービス券の合計枚数を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq M \leq 100
  • 1 \leq A_i \leq 10000
  • 入力はすべて整数

入力

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

N M
A_1 A_2 \ldots A_N
  • 1 行目には、客の人数 N と、 1 人に渡す枚数の上限 M がスペース区切りで与えられる。
  • 2 行目には、各客の支払い額 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。

出力

高橋君が渡したサービス券の合計枚数を 1 行で出力せよ。


入力例 1

3 5
150 320 90

出力例 1

4

入力例 2

1 2
350

出力例 2

2

入力例 3

2 1
100 99

出力例 3

1

入力例 4

3 5
150 320 100

出力例 4

5

入力例 5

1 100
1

出力例 5

0

Score : 200 pts

Problem Statement

N customers visited Takahashi's shop, and the i-th customer paid A_i yen.

Takahashi gives one service ticket for every 100 yen paid. That is, a customer who paid A_i yen receives a number of tickets equal to the quotient of A_i divided by 100 (rounded down to the nearest integer). However, the number of tickets given to a single customer is at most M.

Find the total number of service tickets Takahashi gave out.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq M \leq 100
  • 1 \leq A_i \leq 10000
  • All values in the input are integers.

Input

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

N M
A_1 A_2 \ldots A_N
  • The first line contains the number of customers N and the upper limit M on the number of tickets given to one person, separated by a space.
  • The second line contains the amounts paid by each customer, A_1, A_2, \ldots, A_N, separated by spaces.

Output

Print the total number of service tickets Takahashi gave out in one line.


Sample Input 1

3 5
150 320 90

Sample Output 1

4

Sample Input 2

1 2
350

Sample Output 2

2

Sample Input 3

2 1
100 99

Sample Output 3

1

Sample Input 4

3 5
150 320 100

Sample Output 4

5

Sample Input 5

1 100
1

Sample Output 5

0
B - The Count's Vault

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233 点

問題文

伯爵の金庫には最初 X 枚の金貨が入っています。これから N 回の取引が順に行われます。 i 回目の取引は文字 T_i と整数 A_i で表されます。

  • T_i が D のとき、金庫に金貨を A_i 枚入れます。
  • T_i が W のとき、金庫から金貨を A_i 枚取り出そうとします。ただし、金庫に入っている金貨が A_i 枚より少ない場合、この取引は断られ、金庫の中身は変わりません。

各取引が終わった直後に金庫に入っている金貨の枚数を、順番に出力してください。

制約

  • 1 \leq N \leq 100
  • 0 \leq X \leq 1000
  • T_i は D または W
  • 1 \leq A_i \leq 1000
  • N 、 X 、 A_i は整数

入力

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

N X
T_1 A_1
T_2 A_2
\vdots
T_N A_N
  • 1 行目には、取引の回数 N と最初の金貨の枚数 X がスペース区切りで与えられる。
  • 2 行目から N 行にわたり、 1 + i 行目には i 回目の取引の種類 T_i と枚数 A_i がスペース区切りで与えられる。

出力

N 行出力せよ。 i 行目には i 回目の取引が終わった直後の金貨の枚数を出力せよ。


入力例 1

4 10
D 5
W 20
W 8
D 1

出力例 1

15
15
7
8

入力例 2

1 0
W 3

出力例 2

0

入力例 3

3 100
W 30
W 30
D 1000

出力例 3

70
40
1040

入力例 4

2 100
W 6
W 2

出力例 4

94
92

入力例 5

3 100
W 30
W 1
D 1000

出力例 5

70
69
1069

Score : 233 pts

Problem Statement

The Count's vault initially contains X gold coins. N transactions will now be performed in order. The i-th transaction is described by a character T_i and an integer A_i.

  • When T_i is D, deposit A_i gold coins into the vault.
  • When T_i is W, attempt to withdraw A_i gold coins from the vault. However, if the vault contains fewer than A_i coins, this transaction is declined and the contents of the vault do not change.

Print the number of gold coins in the vault immediately after each transaction, in order.

Constraints

  • 1 \leq N \leq 100
  • 0 \leq X \leq 1000
  • T_i is D or W
  • 1 \leq A_i \leq 1000
  • N, X, and A_i are integers

Input

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

N X
T_1 A_1
T_2 A_2
\vdots
T_N A_N
  • The first line contains the number of transactions N and the initial number of coins X, separated by a space.
  • For each of the next N lines, line 1 + i contains the type T_i and the amount A_i of the i-th transaction, separated by a space.

Output

Print N lines. The i-th line should contain the number of coins in the vault immediately after the i-th transaction.


Sample Input 1

4 10
D 5
W 20
W 8
D 1

Sample Output 1

15
15
7
8

Sample Input 2

1 0
W 3

Sample Output 2

0

Sample Input 3

3 100
W 30
W 30
D 1000

Sample Output 3

70
40
1040

Sample Input 4

2 100
W 6
W 2

Sample Output 4

94
92

Sample Input 5

3 100
W 30
W 1
D 1000

Sample Output 5

70
69
1069
C - Draft Meeting

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

プロ野球のドラフト会議が行われます。あなたは球団 1(高橋球団)のファンで、高橋球団が獲得する選手に注目しています。

今年のドラフト候補選手は N 人おり、i 番目の選手の評価値は V_i です。この評価値は各選手の将来性を数値化したもので、高いほど優秀な選手とされています。なお、どの 2 人の選手も異なる評価値を持ちます。

ドラフト会議には M 球団が参加しており、球団には 1 から M までの番号が付けられています。今回のドラフトは入札制ではなく順番指名制で、以下のルールに従って進行します:

  • 球団 1, 球団 2, \ldots, 球団 M の順を 1 巡とし、この順番を繰り返します。
  • 各球団は自分の番が来たとき、まだ指名されていない選手が 1 人以上いるならば、その中から最も評価値の高い選手をちょうど 1 人指名し、獲得します。すべての球団は同じ評価基準に基づき行動し、指名する選手を自由に選ぶことはできません。また、指名をスキップすることもできません。
  • 一度指名された選手を、別の球団が再び指名することはできません。
  • ある球団の番が来たとき、まだ指名されていない選手が 1 人もいなければ、その時点でドラフト会議は終了します。巡の途中であっても即座に終了します。

まとめると、各球団は順番に、その時点で残っている選手の中から最も評価値の高い選手を 1 人ずつ獲得していき、選手がいなくなった時点で終了します。

高橋球団(球団 1)が最終的に獲得するすべての選手の評価値の合計を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq M \leq N
  • 1 \leq V_i \leq 10^9
  • V_i はすべて異なる
  • 入力はすべて整数

入力

N M
V_1 V_2 \cdots V_N
  • 1 行目には、候補選手の人数を表す整数 N と、ドラフト会議に参加する球団の数を表す整数 M が、スペース区切りで与えられる。
  • 2 行目には、各選手の評価値を表す整数 V_1, V_2, \ldots, V_N が、スペース区切りで与えられる。

出力

高橋球団が獲得する選手の評価値の合計を 1 行で出力してください。


入力例 1

5 2
100 50 80 30 60

出力例 1

190

入力例 2

7 3
500 300 700 200 400 100 600

出力例 2

1200

入力例 3

10 4
15 82 47 91 33 68 24 79 56 10

出力例 3

162

Score : 300 pts

Problem Statement

A professional baseball draft conference is being held. You are a fan of Team 1 (Takahashi Team), and you are interested in the players that Takahashi Team will acquire.

There are N draft candidate players this year, and the i-th player has an evaluation value of V_i. This evaluation value quantifies each player's potential, and a higher value indicates a more talented player. Note that no two players have the same evaluation value.

M teams are participating in the draft conference, and the teams are numbered from 1 to M. This draft uses a sequential selection system rather than a bidding system, and proceeds according to the following rules:

  • One round consists of the order: Team 1, Team 2, \ldots, Team M, and this order is repeated.
  • When it is a team's turn, if there is at least one player who has not yet been selected, the team selects and acquires exactly one player with the highest evaluation value among the remaining players. All teams act based on the same evaluation criteria and cannot freely choose which player to select. They also cannot skip their selection.
  • A player who has already been selected cannot be selected again by another team.
  • When it is a team's turn and there are no remaining unselected players, the draft conference ends at that point. It ends immediately even if it is in the middle of a round.

In summary, each team takes turns acquiring the player with the highest evaluation value among the remaining players, one at a time, and the process ends when there are no more players left.

Find the total evaluation value of all players that Takahashi Team (Team 1) ultimately acquires.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq M \leq N
  • 1 \leq V_i \leq 10^9
  • All V_i are distinct
  • All input values are integers

Input

N M
V_1 V_2 \cdots V_N
  • The first line contains an integer N representing the number of candidate players and an integer M representing the number of teams participating in the draft conference, separated by a space.
  • The second line contains integers V_1, V_2, \ldots, V_N representing the evaluation values of each player, separated by spaces.

Output

Output the total evaluation value of the players acquired by Takahashi Team in a single line.


Sample Input 1

5 2
100 50 80 30 60

Sample Output 1

190

Sample Input 2

7 3
500 300 700 200 400 100 600

Sample Output 2

1200

Sample Input 3

10 4
15 82 47 91 33 68 24 79 56 10

Sample Output 3

162
D - Order of Carrying Out the Coolers

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

倉庫に N 台の保冷庫があり、1 から N までの番号が付いています。保冷庫 i を倉庫から運び出すには T_i 分かかります。また、保冷庫 i は、運び出す作業が完了するまで、1 分あたり P_i 単位の電力量を消費し続けます。作業中の保冷庫も電力を消費します。

高橋君は時刻 0 に作業を始め、すべての保冷庫を好きな順番で、1 台ずつ運び出します。各保冷庫の作業を途中で中断することはできず、ある保冷庫の作業が終わると直ちに次の保冷庫の作業を始めます。保冷庫の電源は、その保冷庫を運び出す作業が完了した時点で切り、それより前に切ることはできません。

時刻 0 からすべての作業が完了するまでに、保冷庫全体が消費する電力量の合計としてあり得る最小値を求めてください。

制約

  • 1 \leq N \leq 200000
  • 1 \leq T_i,P_i \leq 1000 (1 \leq i \leq N)
  • 入力はすべて整数である。

入力

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

N
T_1 P_1
T_2 P_2
\vdots
T_N P_N
  • 1 行目には保冷庫の台数 N が与えられます。
  • 続く N 行のうち i 行目には、保冷庫 i の搬出にかかる時間 T_i と、1 分あたりの消費電力量 P_i が与えられます。

出力

消費電力量の合計の最小値を出力してください。


入力例 1

2
3 2
1 4

出力例 1

12

入力例 2

2
1 1
4 8

出力例 2

37

入力例 3

4
4 3
2 5
3 2
1 1

出力例 3

54

入力例 4

6
6 4
2 1
3 8
4 4
1 3
5 2

出力例 4

181

入力例 5

1
1000 1000

出力例 5

1000000

Score : 400 pts

Problem Statement

There are N refrigerators in a warehouse, numbered 1 to N. Carrying refrigerator i out of the warehouse takes T_i minutes. Additionally, refrigerator i continues to consume P_i units of power per minute until the work of carrying it out is completed. A refrigerator also consumes power while it is being carried out.

Takahashi starts working at time 0 and carries out all the refrigerators one by one in any order he chooses. The work on each refrigerator cannot be interrupted midway, and as soon as the work on one refrigerator finishes, he immediately begins working on the next refrigerator. The power to a refrigerator is turned off at the moment the work of carrying it out is completed, and it cannot be turned off before then.

Find the minimum possible total power consumed by all refrigerators from time 0 until all work is completed.

Constraints

  • 1 \leq N \leq 200000
  • 1 \leq T_i,P_i \leq 1000 (1 \leq i \leq N)
  • All input values are integers.

Input

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

N
T_1 P_1
T_2 P_2
\vdots
T_N P_N
  • The first line contains the number of refrigerators N.
  • The i-th of the following N lines contains the time T_i required to carry out refrigerator i and its power consumption per minute P_i.

Output

Print the minimum possible total power consumption.


Sample Input 1

2
3 2
1 4

Sample Output 1

12

Sample Input 2

2
1 1
4 8

Sample Output 2

37

Sample Input 3

4
4 3
2 5
3 2
1 1

Sample Output 3

54

Sample Input 4

6
6 4
2 1
3 8
4 4
1 3
5 2

Sample Output 4

181

Sample Input 5

1
1000 1000

Sample Output 5

1000000
E - Intervals with Two Shortest Sticks

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 466 点

問題文

N 本の棒が一列に並んでおり、左から i 番目の棒の長さは A_i です。

連続する空でない区間の棒を選びます。選んだ棒のうち最も短いものの長さを m とします。次の二つの条件をともに満たす区間は何個ありますか。

  • 選んだ棒の中に、長さが m である棒がちょうど 2 本ある。
  • 選んだ棒をそれぞれ長さ m の棒に切り分けると、どの棒にも余りが出ない。長さがもともと m である棒は、そのままでよい。

区間の左端または右端の位置が異なれば、異なる区間として数えます。

制約

  • 1\leq N\leq 200000
  • 1\leq A_i\leq 10^9 (1\leq i\leq N)
  • 入力はすべて整数である。

入力

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

N
A_1 A_2 \ldots A_N
  • 1 行目には棒の本数 N が与えられる。
  • 2 行目には各棒の長さが左から順に与えられる。

出力

条件を満たす区間の個数を整数で出力せよ。


入力例 1

3
2 4 2

出力例 1

1

入力例 2

3
6 10 6

出力例 2

0

入力例 3

5
2 4 2 8 2

出力例 3

4

入力例 4

9
6 12 6 3 9 3 6 18 6

出力例 4

18

入力例 5

1
1

出力例 5

0

Score : 466 pts

Problem Statement

There are N sticks arranged in a row, and the length of the i-th stick from the left is A_i.

We choose a contiguous, non-empty interval of sticks. Let m be the minimum length among the chosen sticks. How many intervals satisfy both of the following two conditions?

  • Among the chosen sticks, there are exactly 2 sticks of length m.
  • When each chosen stick is cut into sticks of length m, no stick leaves any remainder. Sticks that originally have length m can be left as they are.

Two intervals are counted as distinct if their left endpoints or right endpoints differ.

Constraints

  • 1\leq N\leq 200000
  • 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
A_1 A_2 \ldots A_N
  • The first line contains the number of sticks, N.
  • The second line contains the length of each stick in order from left to right.

Output

Print the number of intervals satisfying the conditions as an integer.


Sample Input 1

3
2 4 2

Sample Output 1

1

Sample Input 2

3
6 10 6

Sample Output 2

0

Sample Input 3

5
2 4 2 8 2

Sample Output 3

4

Sample Input 4

9
6 12 6 3 9 3 6 18 6

Sample Output 4

18

Sample Input 5

1
1

Sample Output 5

0