Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる文字列 S が与えられます。
S から a
, e
, i
, o
, u
をすべて取り除いて得られる文字列を出力してください。
なお、S は a
, e
, i
, o
, u
以外の文字を一つ以上含みます。
制約
- S は英小文字からなる長さ 1 以上 100 以下の文字列
- S は
a
,e
,i
,o
,u
以外の文字を一つ以上含む
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder
出力例 1
tcdr
S = atcoder
のとき、1, 4, 6 文字目を取り除いて tcdr
を得ます。
入力例 2
xyz
出力例 2
xyz
入力例 3
aaaabbbbcccc
出力例 3
bbbbcccc
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English letters.
Remove all occurrences of a
, e
, i
, o
, u
from S and print the resulting string.
S contains at least one character other than a
, e
, i
, o
, u
.
Constraints
- S is a string of length between 1 and 100, inclusive, consisting of lowercase English letters.
- S contains at least one character other than
a
,e
,i
,o
,u
.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder
Sample Output 1
tcdr
For S = atcoder
, remove the 1-st, 4-th, and 6-th characters to get tcdr
.
Sample Input 2
xyz
Sample Output 2
xyz
Sample Input 3
aaaabbbbcccc
Sample Output 3
bbbbcccc
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 王国では、競技プログラミングの実力を測る検定試験が実施されています。
試験は 100 点満点であり、点数が高ければ高いほど、高いランクが認定されます。
ランクは以下のように定められています。
- 0 点以上 40 点未満のとき、初級
- 40 点以上 70 点未満のとき、中級
- 70 点以上 90 点未満のとき、上級
- 90 点以上のとき、エキスパート
高橋君は、この検定試験を受験し、X 点を取りました。
高橋君が認定されたランクより一つ高いランクとなるためには最低であと何点必要か求めてください。ただし、高橋君がエキスパートと認定された場合、それより高いランクは存在しないため expert
と出力してください。
制約
- 0 \leq X \leq 100
- X は整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
答えを出力せよ。
入力例 1
56
出力例 1
14
高橋君は 56 点を取り、中級と認定されました。一つ高いランクである上級となるためには、最低であと 14 点必要です。
入力例 2
32
出力例 2
8
入力例 3
0
出力例 3
40
入力例 4
100
出力例 4
expert
高橋君は満点を取り、エキスパートと認定されました。これより高いランクは存在しないため、expert
と出力します。
Score : 100 points
Problem Statement
In the Kingdom of AtCoder, there is a standardized test of competitive programming proficiency.
An examinee will get a score out of 100 and obtain a rank according to the score, as follows:
- Novice, for a score not less than 0 but less than 40;
- Intermediate, for a score not less than 40 but less than 70;
- Advanced, for a score not less than 70 but less than 90;
- Expert, for a score not less than 90.
Takahashi took this test and got X points.
Find the minimum number of extra points needed to go up one rank higher. If, however, his rank was Expert, print expert
, as there is no higher rank than that.
Constraints
- 0 \leq X \leq 100
- X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print the answer.
Sample Input 1
56
Sample Output 1
14
He got 56 points and was certified as Intermediate. In order to reach the next rank of Advanced, he needs at least 14 more points.
Sample Input 2
32
Sample Output 2
8
Sample Input 3
0
Sample Output 3
40
Sample Input 4
100
Sample Output 4
expert
He got full points and was certified as Expert. There is no rank higher than that, so print expert
.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
整数 N と長さ N の数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。
クエリが Q 個与えられるので、与えられた順番に処理してください。 クエリは次の 2 種類のいずれかです。
1 k x
: A _ k の値を x に変更する。2 k
: A _ k の値を出力する。
制約
- 1 \leq N \leq 10 ^ 5
- 1 \leq Q \leq 10 ^ 5
- 0 \leq A _ i \leq 10 ^ 9\ (1\leq i\leq N)
- どのクエリについても、1\leq k\leq N
- 1 番目の形式のクエリについて、0\leq x\leq 10 ^ 9
- 2 番目の形式のクエリが 1 つ以上存在する
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N Q \operatorname{query} _ 1 \operatorname{query} _ 2 \vdots \operatorname{query} _ Q
ただし、\operatorname{query} _ i は i 個目のクエリを表しており、次の形式のいずれかで与えられる。
1 k x
2 k
出力
2 番目の形式のクエリの回数を q 回として q 行出力せよ。 j\ (1\leq j\leq q) 行目には、2 番目の形式のクエリのうち j 個目のものに対する答えを出力せよ。
入力例 1
3 1 3 5 7 2 2 2 3 1 3 0 2 3 1 2 8 2 2 2 1
出力例 1
3 5 0 8 1
はじめ、A=(1,3,5) です。
- 1 つめのクエリにおいて、A=(1,3,5) です。A _ 2=3 なので、3 を出力します。
- 2 つめのクエリにおいて、A=(1,3,5) です。A _ 3=5 なので、5 を出力します。
- 3 つめのクエリでは、A _ 3 の値を 0 に変更し、A=(1,3,0) となります。
- 4 つめのクエリにおいて、A=(1,3,0) です。A _ 3=0 なので、0 を出力します。
- 5 つめのクエリでは、A _ 2 の値を 8 に変更し、A=(1,8,0) となります。
- 6 つめのクエリにおいて、A=(1,8,0) です。A _ 2=8 なので、8 を出力します。
- 7 つめのクエリにおいて、A=(1,8,0) です。A _ 1=1 なので、1 を出力します。
入力例 2
5 22 2 16 7 30 10 1 4 0 1 5 0 2 2 2 3 2 4 2 5 1 4 100 1 5 100 2 3 2 4
出力例 2
2 16 0 0 16 100
入力例 3
7 478 369 466 343 541 42 165 20 2 1 1 7 729 1 6 61 1 6 838 1 3 319 1 4 317 2 4 1 1 673 1 3 176 1 5 250 1 1 468 2 6 1 7 478 1 5 595 2 6 1 6 599 1 6 505 2 3 2 5 2 1
出力例 3
478 317 838 838 176 595 468
Score : 200 points
Problem Statement
You are given an integer N and a sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.
Given Q queries, process them in the given order. Each query is of one of the following two kinds:
1 k x
: set the value A _ k to x.2 k
: print the value A _ k.
Constraints
- 1 \leq N \leq 10 ^ 5
- 1 \leq Q \leq 10 ^ 5
- 0 \leq A _ i \leq 10 ^ 9\ (1\leq i\leq N)
- 1\leq k\leq N for all queries.
- 0\leq x\leq 10 ^ 9 for all queries of the first kind.
- There is at least one query of the second kind.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A _ 1 A _ 2 \ldots A _ N Q \operatorname{query} _ 1 \operatorname{query} _ 2 \vdots \operatorname{query} _ Q
Here, \operatorname{query} _ i denotes the i-th query, given in one of the following formats:
1 k x
2 k
Output
Print q lines, where q is the number of queries of the second kind. The j-th (1\leq j\leq q) line should contain the response to the j-th such query.
Sample Input 1
3 1 3 5 7 2 2 2 3 1 3 0 2 3 1 2 8 2 2 2 1
Sample Output 1
3 5 0 8 1
Initially, A=(1,3,5).
- For the 1-st query, A=(1,3,5), where A _ 2=3, so 3 should be printed.
- For the 2-nd query, A=(1,3,5), where A _ 3=5, so 5 should be printed.
- The 3-rd query sets the value A _ 3 to 0, making A=(1,3,0).
- For the 4-th query, A=(1,3,0), where A _ 3=0, so 0 should be printed.
- The 5-th query sets the value A _ 2 to 8, making A=(1,8,0).
- For the 6-th query, A=(1,8,0), where A _ 2=8, so 8 should be printed.
- For the 7-th query, A=(1,8,0), where A _ 1=1, so 1 should be printed.
Sample Input 2
5 22 2 16 7 30 10 1 4 0 1 5 0 2 2 2 3 2 4 2 5 1 4 100 1 5 100 2 3 2 4
Sample Output 2
2 16 0 0 16 100
Sample Input 3
7 478 369 466 343 541 42 165 20 2 1 1 7 729 1 6 61 1 6 838 1 3 319 1 4 317 2 4 1 1 673 1 3 176 1 5 250 1 1 468 2 6 1 7 478 1 5 595 2 6 1 6 599 1 6 505 2 3 2 5 2 1
Sample Output 3
478 317 838 838 176 595 468
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の文字列 S が与えられます。
S に連続して含まれる na
を全て nya
に置き換えて得られる文字列を答えてください。
制約
- N は 1 以上 1000 以下の整数
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
4 naan
出力例 1
nyaan
naan
に連続して含まれる na
を全て nya
に置き換えて得られる文字列は nyaan
です。
入力例 2
4 near
出力例 2
near
S に na
が連続して含まれないこともあります。
入力例 3
8 national
出力例 3
nyationyal
Score : 200 points
Problem Statement
You are given a string S of length N.
Find the string obtained by replacing all contiguous occurrences of na
in S with nya
.
Constraints
- N is an integer between 1 and 1000, inclusive.
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
4 naan
Sample Output 1
nyaan
Replacing all contiguous occurrences of na
in naan
with nya
results in the string nyaan
.
Sample Input 2
4 near
Sample Output 2
near
S may not contain a contiguous na
.
Sample Input 3
8 national
Sample Output 3
nyationyal
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
縦 H マス, 横 W マスのグリッドがあります。上から i 行目、左から j 列目のマスを (i, j) と呼びます。
はじめ、グリッド上には、ある 縦横 2 マス以上 の部分長方形の内部にあるマスにクッキーが 1 枚ずつ置かれていて、それ以外のマスにはクッキーが置かれていません。
形式的に説明すると、以下の条件を全て満たす 4 つの整数の組 (a,b,c,d) がただ 1 つ存在します。
- 1 \leq a \lt b \leq H
- 1 \leq c \lt d \leq W
- グリッド上のマスのうち、a \leq i \leq b, c \leq j \leq d を満たす全てのマス (i, j) にはクッキーが 1 枚ずつ置かれていて、それ以外のマスにはクッキーが置かれていない。
ところが、すぬけ君がグリッド上のクッキーのどれか 1 枚を取って食べてしまいました。
すぬけ君がクッキーを取ったマスは、クッキーが置かれていない状態に変わります。
すぬけ君がクッキーを食べた後のグリッドの状態が入力として与えられます。
マス (i, j) の状態は文字 S_{i,j} として与えられて、#
はクッキーが置かれているマスを, .
はクッキーが置かれていないマスを意味します。
すぬけ君が食べたクッキーが元々置かれていたマスを答えてください。(答えは一意に定まります。)
制約
- 2 \leq H, W \leq 500
- S_{i,j} は
#
または.
入力
入力は以下の形式で標準入力から与えられる。
H W S_{1,1}S_{1,2}\dotsS_{1,W} S_{2,1}S_{2,2}\dotsS_{2,W} \vdots S_{H,1}S_{H,2}\dotsS_{H,W}
出力
すぬけ君が食べたクッキーが元々置かれていたマスを (i, j) とする。i, j をこの順に空白区切りで出力せよ。
入力例 1
5 6 ...... ..#.#. ..###. ..###. ......
出力例 1
2 4
はじめ、クッキーは (2, 3) を左上、(4, 5) を右下とする部分長方形の内部にあるマスに置かれていて、すぬけ君は (2, 4) にあるクッキーを食べたことがわかります。よって (2, 4) を出力します。
入力例 2
3 2 #. ## ##
出力例 2
1 2
はじめ、クッキーは (1, 1) を左上、(3, 2) を右下とする部分長方形の内部にあるマスに置かれていて、すぬけ君は (1, 2) にあるクッキーを食べたことがわかります。
入力例 3
6 6 ..#### ..##.# ..#### ..#### ..#### ......
出力例 3
2 5
Score : 300 points
Problem Statement
There is a grid with H rows and W columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.
Initially, there was one cookie on each square inside a rectangle whose height and width were at least 2 squares long, and no cookie on the other squares.
Formally, there was exactly one quadruple of integers (a,b,c,d) that satisfied all of the following conditions.
- 1 \leq a \lt b \leq H
- 1 \leq c \lt d \leq W
- There was one cookie on each square (i, j) such that a \leq i \leq b, c \leq j \leq d, and no cookie on the other squares.
However, Snuke took and ate one of the cookies on the grid.
The square that contained that cookie is now empty.
As the input, you are given the state of the grid after Snuke ate the cookie.
The state of the square (i, j) is given as the character S_{i,j}, where #
means a square with a cookie, and .
means a square without one.
Find the square that contained the cookie eaten by Snuke. (The answer is uniquely determined.)
Constraints
- 2 \leq H, W \leq 500
- S_{i,j} is
#
or.
.
Input
The input is given from Standard Input in the following format:
H W S_{1,1}S_{1,2}\dotsS_{1,W} S_{2,1}S_{2,2}\dotsS_{2,W} \vdots S_{H,1}S_{H,2}\dotsS_{H,W}
Output
Let (i, j) the square contained the cookie eaten by Snuke. Print i and j in this order, separated by a space.
Sample Input 1
5 6 ...... ..#.#. ..###. ..###. ......
Sample Output 1
2 4
Initially, cookies were on the squares inside the rectangle with (2, 3) as the top-left corner and (4, 5) as the bottom-right corner, and Snuke ate the cookie on (2, 4). Thus, you should print (2, 4).
Sample Input 2
3 2 #. ## ##
Sample Output 2
1 2
Initially, cookies were placed on the squares inside the rectangle with (1, 1) as the top-left corner and (3, 2) as the bottom-right corner, and Snuke ate the cookie at (1, 2).
Sample Input 3
6 6 ..#### ..##.# ..#### ..#### ..#### ......
Sample Output 3
2 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
xy 平面上に 1 から N までの番号が付いた N 個の点があります。
点 i は座標 (X_i,Y_i) にあり、相異なる 2 点は異なる位置に存在します。
この N 点から 3 点を選ぶとき、選ばれた 3 点を線分で結んだ図形が正の面積を持つ三角形になるような点の選び方の総数を求めてください。
制約
- 入力は全て整数である
- 3 \le N \le 300
- -10^9 \le X_i,Y_i \le 10^9
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
出力
答えを整数として出力せよ。
入力例 1
4 0 1 1 3 1 1 -1 -1
出力例 1
3
点を図示すると、以下のようになります。
三角形をなすような点の選び方は、 \{1,2,3\},\{1,3,4\},\{2,3,4\} の 3 つです。
入力例 2
20 224 433 987654321 987654321 2 0 6 4 314159265 358979323 0 0 -123456789 123456789 -1000000000 1000000000 124 233 9 -6 -4 0 9 5 -7 3 333333333 -333333333 -9 -1 7 -10 -1 5 324 633 1000000000 -1000000000 20 0
出力例 2
1124
Score : 300 points
Problem Statement
In the xy-plane, we have N points numbered 1 through N.
Point i is at the coordinates (X_i,Y_i). Any two different points are at different positions.
Find the number of ways to choose three of these N points so that connecting the chosen points with segments results in a triangle with a positive area.
Constraints
- All values in input are integers.
- 3 \le N \le 300
- -10^9 \le X_i,Y_i \le 10^9
- (X_i,Y_i) \neq (X_j,Y_j) if i \neq j.
Input
Input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
Output
Print the answer as an integer.
Sample Input 1
4 0 1 1 3 1 1 -1 -1
Sample Output 1
3
The figure below illustrates the points.
There are three ways to choose points that form a triangle: \{1,2,3\},\{1,3,4\},\{2,3,4\}.
Sample Input 2
20 224 433 987654321 987654321 2 0 6 4 314159265 358979323 0 0 -123456789 123456789 -1000000000 1000000000 124 233 9 -6 -4 0 9 5 -7 3 333333333 -333333333 -9 -1 7 -10 -1 5 324 633 1000000000 -1000000000 20 0
Sample Output 2
1124
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
頂点数 2^{10^{100}}-1 の完全二分木があり、頂点には 1,2,...,2^{10^{100}}-1 の番号がついています。
頂点 1 が根であり、各 1\leq i < 2^{10^{100}-1} について、頂点 i は 頂点 2i を左の子、頂点 2i+1 を右の子として持ちます。
高橋君は最初頂点 X におり、N 回移動を行います。移動は文字列 S により表され、i 回目の移動は次のように行います。
- S の i 番目の文字が
U
のとき、今いる頂点の親に移動する - S の i 番目の文字が
L
のとき、今いる頂点の左の子に移動する - S の i 番目の文字が
R
のとき、今いる頂点の右の子に移動する
N 回の移動後に高橋君がいる頂点の番号を求めてください。なお、答えが 10^{18} 以下になるような入力のみが与えられます。
制約
- 1 \leq N \leq 10^6
- 1 \leq X \leq 10^{18}
- N,X は整数
- S は長さ N であり、
U
,L
,R
のみからなる - 高橋君が根にいるとき、親に移動しようとすることはない
- 高橋君が葉にいるとき、子に移動しようとすることはない
- 高橋君が N 回の移動後にいる頂点の番号は 10^{18} 以下である
入力
入力は以下の形式で標準入力から与えられる。
N X S
出力
答えを出力せよ。
入力例 1
3 2 URL
出力例 1
6
完全二分木は次のような構造をしています。
各移動により、高橋君がいる頂点の番号は 2 \to 1 \to 3 \to 6 と変化します。
入力例 2
4 500000000000000000 RRUU
出力例 2
500000000000000000
移動の途中過程において、高橋君がいる頂点の番号が 10^{18} を超えることもあります。
入力例 3
30 123456789 LRULURLURLULULRURRLRULRRRUURRU
出力例 3
126419752371
Score : 400 points
Problem Statement
There is a perfect binary tree with 2^{10^{100}}-1 vertices, numbered 1,2,...,2^{10^{100}}-1.
Vertex 1 is the root. For each 1\leq i < 2^{10^{100}-1}, Vertex i has two children: Vertex 2i to the left and Vertex 2i+1 to the right.
Takahashi starts at Vertex X and performs N moves, represented by a string S. The i-th move is as follows.
- If the i-th character of S is
U
, go to the parent of the vertex he is on now. - If the i-th character of S is
L
, go to the left child of the vertex he is on now. - If the i-th character of S is
R
, go to the right child of the vertex he is on now.
Find the index of the vertex Takahashi will be on after N moves. In the given cases, it is guaranteed that the answer is at most 10^{18}.
Constraints
- 1 \leq N \leq 10^6
- 1 \leq X \leq 10^{18}
- N and X are integers.
- S has a length of N and consists of
U
,L
, andR
. - When Takahashi is at the root, he never attempts to go to the parent.
- When Takahashi is at a leaf, he never attempts to go to a child.
- The index of the vertex Takahashi is on after N moves is at most 10^{18}.
Input
Input is given from Standard Input in the following format:
N X S
Output
Print the answer.
Sample Input 1
3 2 URL
Sample Output 1
6
The perfect binary tree has the following structure.
In the three moves, Takahashi goes 2 \to 1 \to 3 \to 6.
Sample Input 2
4 500000000000000000 RRUU
Sample Output 2
500000000000000000
During the process, Takahashi may be at a vertex whose index exceeds 10^{18}.
Sample Input 3
30 123456789 LRULURLURLULULRURRLRULRRRUURRU
Sample Output 3
126419752371
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
そうめん流しのイベントに N 人の人が集まりました。人は一列に並んでおり、先頭から順に 1 から N の番号がついています。
そうめん流しでは次の出来事が M 回起こります。
- 時刻 T_i に 量 W_i のそうめんを流す。列の先頭にいる人がその全てを得る(誰も列に並んでいない場合は、誰もそのそうめんを得ない)。その人はいったん列から外れ、時刻 T_i+S_i に列の元の位置に戻ってくる。
時刻 X に列に戻ってくる人は、時刻 X には列に並んでいるとみなします。
M 回の出来事が全て行われたあと、それぞれの人が合計でどれだけそうめんを得ることができたか答えてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 <T_1 <\ldots < T_M \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq W_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M T_1 W_1 S_1 \vdots T_M W_M S_M
出力
N 行出力せよ。 i 行目には人 i が得たそうめんの量を出力せよ。
入力例 1
3 5 1 1 3 2 10 100 4 100 10000 10 1000 1000000000 100 1000000000 1
出力例 1
101 10 1000
次のように進行します。
- 時刻 1 に量 1 のそうめんが流される。列には人 1,2,3 が並んでおり、先頭の人 1 がそうめんを得て列から外れる。
- 時刻 2 に量 10 のそうめんが流される。列には人 2,3 が並んでおり、先頭の人 2 がそうめんを得て列から外れる。
- 時刻 4 に人 1 が列に戻ってくる。
- 時刻 4 に量 100 のそうめんが流される。列には人 1,3 が並んでおり、先頭の人 1 がそうめんを得て列から外れる。
- 時刻 10 に量 1000 のそうめんが流される。列には人 3 が並んでおり、先頭の人 3 がそうめんを得て列から外れる。
- 時刻 100 に量 1000000000 のそうめんが流される。列には誰も並んでいないため、誰もこのそうめんを得ない。
- 時刻 102 に人 2 が列に戻ってくる。
- 時刻 10004 に人 1 が列に戻ってくる。
- 時刻 1000000010 に人 3 が列に戻ってくる。
それぞれの人が得たそうめんの量の合計は、101,10,1000 です。
入力例 2
3 1 1 1 1
出力例 2
1 0 0
入力例 3
1 8 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8
出力例 3
15
Score : 475 points
Problem Statement
There are N people gathered for an event called Flowing Noodles. The people are lined up in a row, numbered 1 to N in order from front to back.
During the event, the following occurrence happens M times:
- At time T_i, a quantity W_i of noodles is flown down. The person at the front of the row gets all of it (if no one is in the row, no one gets it). That person then steps out of the row and returns to their original position in the row at time T_i+S_i.
A person who returns to the row at time X is considered to be in the row at time X.
After all the M occurrences, report the total amount of noodles each person has got.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 <T_1 <\ldots < T_M \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq W_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M T_1 W_1 S_1 \vdots T_M W_M S_M
Output
Print N lines. The i-th line should contain the amount of noodles person i has got.
Sample Input 1
3 5 1 1 3 2 10 100 4 100 10000 10 1000 1000000000 100 1000000000 1
Sample Output 1
101 10 1000
The event proceeds as follows:
- At time 1, a quantity 1 of noodles is flown down. People 1, 2, and 3 are in the row, and the person at the front, person 1, gets the noodles and steps out of the row.
- At time 2, a quantity 10 of noodles is flown down. People 2 and 3 are in the row, and the person at the front, person 2, gets the noodles and steps out of the row.
- At time 4, person 1 returns to the row.
- At time 4, a quantity 100 of noodles is flown down. People 1 and 3 are in the row, and the person at the front, person 1, gets the noodles and steps out of the row.
- At time 10, a quantity 1000 of noodles is flown down. Only person 3 is in the row, and the person at the front, person 3, gets the noodles and steps out of the row.
- At time 100, a quantity 1000000000 of noodles is flown down. No one is in the row, so no one gets these noodles.
- At time 102, person 2 returns to the row.
- At time 10004, person 1 returns to the row.
- At time 1000000010, person 3 returns to the row.
The total amounts of noodles people 1, 2, and 3 have got are 101, 10, and 1000, respectively.
Sample Input 2
3 1 1 1 1
Sample Output 2
1 0 0
Sample Input 3
1 8 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8
Sample Output 3
15
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ L のパンが 1 つあり、これを N 人の子供たちに切り分けます。 i 番目 (1\leq i\leq N) の子供は長さ A_i のパンを欲しがっています。
そこで、高橋君は次の操作を繰り返して、長さ A_1,A_2,\ldots,A_N のパンを切り出して配ることにしました。
長さ k のパン 1 つと 1 以上 k-1 以下の整数 x を選ぶ。選んだパンを長さ x のパンと 長さ k-x のパンに切り分ける。
このとき、x の値によらずコストが k かかる。
それぞれの子供に配るパンは長さがちょうど A_i のパン 1 つである必要がありますが、誰にも配られずに余るパンがいくつあっても構いません。
このとき、全ての子供たちにパンを配るために必要な最小のコストを求めてください。
制約
- 2 \leq N \leq 2\times 10^5
- 1\leq A_i\leq 10^9
- A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L A_1 A_2 \ldots A_N
出力
全ての子供たちにパンを配るために必要な最小のコストを出力せよ。
入力例 1
5 7 1 2 1 2 1
出力例 1
16
高橋君は次のようにしてパンを切り分けて配ることができます。
- 長さ 7 のパンと整数 x=3 を選ぶ。パンは長さ 3 のパンと長さ 4 のパンに切り分けられる。 (コスト 7 )
- 長さ 3 のパンと整数 x=1 を選ぶ。パンは長さ 1 のパンと長さ 2 のパンに切り分けられる。前者を 1 番目の子供に配る。 (コスト 3 )
- 長さ 2 のパンと整数 x=1 を選ぶ。パンは長さ 1 のパン 2 つに切り分けられる。これを 3,5 番目の子供に配る。 (コスト 2 )
- 長さ 4 のパンと整数 x=2 を選ぶ。パンは長さ 2 のパン 2 つに切り分けられる。これを 2,4 番目の子供に配る。 (コスト 4 )
このとき、コストは 7+3+2+4=16 かかり、これが最小です。 また、余るパンはありません。
入力例 2
3 1000000000000000 1000000000 1000000000 1000000000
出力例 2
1000005000000000
それぞれの子供に配るパンの長さはちょうど A_i でなければならない事に注意してください。
Score : 500 points
Problem Statement
We have a loaf of bread of length L, which we will cut and distribute to N children.
The i-th child (1\leq i\leq N) wants a loaf of length A_i.
Now, Takahashi will repeat the operation below to cut the loaf into lengths A_1, A_2, \ldots, A_N for the children.
Choose a loaf of length k and an integer x between 1 and k-1 (inclusive). Cut the loaf into two loaves of length x and k-x.
This operation incurs a cost of k regardless of the value of x.
Each child i must receive a loaf of length exactly A_i, but it is allowed to leave some loaves undistributed.
Find the minimum cost needed to distribute loaves to all children.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1\leq A_i\leq 10^9
- A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L A_1 A_2 \ldots A_N
Output
Print the minimum cost needed to distribute loaves to all children.
Sample Input 1
5 7 1 2 1 2 1
Sample Output 1
16
Takahashi can cut the loaf for the children as follows.
- Choose the loaf of length 7 and x=3, cutting it into loaves of length 3 and 4 for a cost of 7.
- Choose the loaf of length 3 and x=1, cutting it into loaves of length 1 and 2 for a cost of 3. Give the former to the 1-st child.
- Choose the loaf of length 2 and x=1, cutting it into two loaves of length 1 for a cost of 2. Give them to the 3-rd and 5-th children.
- Choose the loaf of length 4 and x=2, cutting it into two loaves of length 2 for a cost of 4. Give them to the 2-nd and 4-th children.
This incurs a cost of 7+3+2+4=16, which is the minimum possible. There will be no leftover loaves.
Sample Input 2
3 1000000000000000 1000000000 1000000000 1000000000
Sample Output 2
1000005000000000
Note that each child i must receive a loaf of length exactly A_i.