実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君は植物を育てています。その植物の発芽時の高さは 0\,\mathrm{cm} です。発芽した日を 0 日目としたとき、発芽してから i (0 \le i) 日目の夜には 2^i\,\mathrm{cm} 植物の高さが伸びます。
高橋君の身長は H\,\mathrm{cm} です。
高橋君は毎朝この植物と背比べをします。植物の高さが高橋君の身長より高くなるのは発芽から何日目の朝か求めてください。
制約
- 1 \leq H \leq 10^{9}
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
H
出力
植物の高さが高橋君の身長より高くなる日は発芽から何日目の朝か出力せよ。
入力例 1
54
出力例 1
6
植物が発芽してからの 1 日ごとの朝の高さは 1\,\mathrm{cm},3\,\mathrm{cm},7\,\mathrm{cm}, 15\,\mathrm{cm},31\,\mathrm{cm},63\,\mathrm{cm} となります。 6 日目の朝に高橋君より高くなるため、 6 を出力します。
入力例 2
7
出力例 2
4
植物が発芽してから 3 日目の朝の高さは 7\,\mathrm{cm} で、 4 日目の朝の高さは 15\,\mathrm{cm} です。 4 日目の朝に高橋君より高くなるため、 4 を出力します。3 日目の朝のときは高橋君と同じ高さですが、高橋君より高くないことに注意してください。
入力例 3
262144
出力例 3
19
Score : 100 points
Problem Statement
Takahashi is growing a plant. Its height at the time of germination is 0\,\mathrm{cm}. Considering the day of germination as day 0, its height increases by 2^i\,\mathrm{cm} day i's night (0 \le i).
Takahashi's height is H\,\mathrm{cm}.
Every morning, Takahashi measures his height against this plant. Find the first day such that the plant's height is strictly greater than Takahashi's height in the morning.
Constraints
- 1 \leq H \leq 10^{9}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H
Output
Print an integer representing the first day such that the plant's height is greater than Takahashi's height in the morning.
Sample Input 1
54
Sample Output 1
6
The plant's height in the mornings of days 1, 2, 3, 4, 5, 6 will be 1\,\mathrm{cm}, 3\,\mathrm{cm}, 7\,\mathrm{cm}, 15\,\mathrm{cm}, 31\,\mathrm{cm}, 63\,\mathrm{cm}, respectively. The plant becomes taller than Takahashi in the morning day 6, so print 6.
Sample Input 2
7
Sample Output 2
4
The plant's height will be 7\,\mathrm{cm} in the morning of day 3 and 15\,\mathrm{cm} in the morning day 4. The plant becomes taller than Takahashi in the morning of day 4, so print 4. Note that, in the morning of day 3, the plant is as tall as Takahashi, but not taller.
Sample Input 3
262144
Sample Output 3
19
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
正の整数 N が与えられます。
N,N-1,\dots,1 をこの順にカンマ , で区切って出力してください。
制約
- 1\leq N \leq 9
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N,N-1,\dots,1 をこの順にカンマ区切りで出力せよ。
入力例 1
9
出力例 1
9,8,7,6,5,4,3,2,1
入力例 2
5
出力例 2
5,4,3,2,1
入力例 3
1
出力例 3
1
Score : 100 points
Problem Statement
You are given a positive integer N.
Output N, N-1, \dots, 1 in this order, separated by commas ,.
Constraints
- 1 \leq N \leq 9
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Output N, N-1, \dots, 1 in this order, separated by commas.
Sample Input 1
9
Sample Output 1
9,8,7,6,5,4,3,2,1
Sample Input 2
5
Sample Output 2
5,4,3,2,1
Sample Input 3
1
Sample Output 3
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 個の数列 A_1, A_2, \ldots, A_N が与えられます。
数列 A_i の長さは L_i であり A_i = (A_{i,1}, A_{i,2}, \ldots, A_{i,L_i}) です。
その後、整数 X, Y が与えられます。 A_{X,Y} の値を出力してください。
制約
- 1 \le N \le 2 \times 10^5
- 1 \le L_i
- L_i の総和は 2 \times 10^5 以下
- 1 \le A_{i,j} \le 1000
- 1 \le X \le N
- 1 \le Y \le L_X
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
X Y
出力
A_{X,Y} の値を出力せよ。
入力例 1
3 3 10 20 30 1 7 4 5 6 7 8 3 4
出力例 1
8
(A_1, A_2, A_3) = ((10,20,30), (7), (5,6, 7,8)) です。
A_3 = (5, 6, 7, 8) であり、 A_{3,4} = 8 なので 8 を出力してください。
入力例 2
4 2 9 1 3 8 2 6 1 5 2 4 3 2 2
出力例 2
2
A_2 = (8, 2, 6) なので、A_{2,2} = 2 です。
入力例 3
1 5 100 200 300 400 500 1 5
出力例 3
500
Score : 200 points
Problem Statement
You are given N sequences A_1, A_2, \ldots, A_N.
The length of sequence A_i is L_i, and A_i = (A_{i,1}, A_{i,2}, \ldots, A_{i,L_i}).
After that, integers X and Y are given. Output the value of A_{X,Y}.
Constraints
- 1 \le N \le 2 \times 10^5
- 1 \le L_i
- The sum of L_i is at most 2 \times 10^5.
- 1 \le A_{i,j} \le 1000
- 1 \le X \le N
- 1 \le Y \le L_X
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
X Y
Output
Output the value of A_{X,Y}.
Sample Input 1
3 3 10 20 30 1 7 4 5 6 7 8 3 4
Sample Output 1
8
We have (A_1, A_2, A_3) = ((10,20,30), (7), (5,6, 7,8)).
Since A_3 = (5, 6, 7, 8) and A_{3,4} = 8, output 8.
Sample Input 2
4 2 9 1 3 8 2 6 1 5 2 4 3 2 2
Sample Output 2
2
Since A_2 = (8, 2, 6), we have A_{2,2} = 2.
Sample Input 3
1 5 100 200 300 400 500 1 5
Sample Output 3
500
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
一直線状の倉庫があります。この倉庫に 偶数個 の荷物が保管されています。
倉庫の情報は文字列 S として与えらます。
倉庫は区画 1,2,\dots,|S| の |S| 個の区画からなり、 S の各文字は以下の情報を表します。
- S の i 文字目が
#であるとき、区画 i に荷物が 1 つ置かれている。 - S の i 文字目が
.であるとき、区画 i に荷物が置かれていない。
この倉庫にはロボットがあり、このロボットは以下の行動を倉庫から荷物が無くなるまで繰り返します。
- 荷物をその荷物がある区画番号の小さい方から 2 つ回収する。回収された荷物は倉庫の外へ運び出される。
繰り返しの各回で運び出された 2 つの荷物が倉庫のどの区画にあったものかを求めてください。
制約
- S は
#と.からなる長さ 2 以上 1000 以下の文字列 - 倉庫には偶数個の荷物が保管されている
- 倉庫には 2 つ以上の荷物が保管されている
入力
入力は以下の形式で標準入力から与えられる。
S
出力
倉庫に保管されている荷物の総数を m とすると、 m/2 行出力せよ。
そのうち i 行目には、 i 回目の繰り返しで運び出された荷物が元々あった区画の番号を小さい方から順に カンマ区切り で出力せよ。
入力例 1
.#.##..##.#.###....#
出力例 1
2,4 5,8 9,11 13,14 15,20
区画 2,4,5,8,9,11,13,14,15,20 に荷物が保管されています。
- 1 回目の繰り返しでは区画 2,4 にあった荷物が運び出されます。
- 2 回目の繰り返しでは区画 5,8 にあった荷物が運び出されます。
- 3 回目の繰り返しでは区画 9,11 にあった荷物が運び出されます。
- 4 回目の繰り返しでは区画 13,14 にあった荷物が運び出されます。
- 5 回目の繰り返しでは区画 15,20 にあった荷物が運び出されます。
Score : 200 points
Problem Statement
There is a linear warehouse, which stores an even number of packages.
The layout of the warehouse is represented by a string S.
The warehouse has |S| sections, numbered 1,2,\dots,|S|, and the string S describes them as follows:
- When the i-th character of S is
#, one package is placed in section i. - When the i-th character of S is
., no package is placed in section i.
The warehouse has a robot, which repeats the following action until there are no more packages in the warehouse:
- Collect two packages from the sections with the smallest section numbers among the sections containing packages. The collected packages are carried out of the warehouse.
For each iteration, determine which sections of the warehouse the two packages that were carried out were originally located.
Constraints
- S is a string consisting of
#and.with length between 2 and 1000, inclusive. - The warehouse stores an even number of packages.
- The warehouse stores at least two packages.
Input
The input is given from Standard Input in the following format:
S
Output
Let m be the total number of packages stored in the warehouse. Output m/2 lines.
The i-th line should contain the section numbers where the packages carried out in the i-th iteration were originally located, in ascending order, separated by a comma.
Sample Input 1
.#.##..##.#.###....#
Sample Output 1
2,4 5,8 9,11 13,14 15,20
Packages are stored in sections 2,4,5,8,9,11,13,14,15,20.
- In the 1st iteration, packages from sections 2,4 are carried out.
- In the 2nd iteration, packages from sections 5,8 are carried out.
- In the 3rd iteration, packages from sections 9,11 are carried out.
- In the 4th iteration, packages from sections 13,14 are carried out.
- In the 5th iteration, packages from sections 15,20 are carried out.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
正整数 N と、長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
A の空でない連続部分列であって、同じ値を複数個含むようなものが存在するか判定してください。存在するならばそのようなもののうち最も短いものの長さを求めてください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq A_i\leq 10^6 (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
問題文中の条件を満たす連続部分列が存在しないならば -1 と出力せよ。存在するならば、そのようなもののうち最も短いものの長さを出力せよ。
入力例 1
5 3 9 5 3 1
出力例 1
4
(3,9,5,3) と (3,9,5,3,1) が条件を満たします。短いのは (3,9,5,3) で、その長さは 4 です。
入力例 2
4 2 5 3 1
出力例 2
-1
条件を満たす連続部分列は存在しません。
入力例 3
10 1 1 2 3 5 8 13 21 34 55
出力例 3
2
Score : 300 points
Problem Statement
You are given a positive integer N and an integer sequence A = (A_1,A_2,\dots,A_N) of length N.
Determine whether there exists a non-empty (contiguous) subarray of A that has a repeated value, occurring multiple times in A. If such a subarray exists, find the length of the shortest such subarray.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^6 \ (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 \dots A_N
Output
If there is no (contiguous) subarray satisfying the condition in the problem statement, print -1. Otherwise, print the length of the shortest such subarray.
Sample Input 1
5 3 9 5 3 1
Sample Output 1
4
(3,9,5,3) and (3,9,5,3,1) satisfy the condition. The shorter one is (3,9,5,3), which has length 4.
Sample Input 2
4 2 5 3 1
Sample Output 2
-1
There is no subarray that satisfies the condition.
Sample Input 3
10 1 1 2 3 5 8 13 21 34 55
Sample Output 3
2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
長さ N の正整数列 A=(A_1,A_2,\dots,A_N) および正整数 K が与えられます。
1 以上 K 以下の整数のうち、A の中に一度も現れないものの総和を求めてください。
制約
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 5 1 6 3 1
出力例 1
11
1 以上 5 以下の整数のうち、A の中に一度も現れないものは 2,4,5 の 3 つです。
よって、それらの総和である 2+4+5=11 を出力します。
入力例 2
1 3 346
出力例 2
6
入力例 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
出力例 3
12523196466007058
Score: 250 points
Problem Statement
You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer K.
Find the sum of the integers between 1 and K, inclusive, that do not appear in the sequence A.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 5 1 6 3 1
Sample Output 1
11
Among the integers between 1 and 5, three numbers, 2, 4, and 5, do not appear in A.
Thus, print their sum: 2+4+5=11.
Sample Input 2
1 3 346
Sample Output 2
6
Sample Input 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
Sample Output 3
12523196466007058
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
1 から N までの番号が付けられた N 個の商品がベルトコンベア上を流れています。 ベルトコンベアには印字機が取り付けられており、商品 i は今から T_i [μs] 後に印字機の範囲に入り、その D_i [μs] 後に印字機の範囲から出ます。
キーエンスの印字機は、印字機の範囲内にある商品 1 つに一瞬で印字することができます(特に、商品が印字機の範囲に入る瞬間や範囲から出る瞬間に印字することも可能です)。 ただし、1 度印字すると、次に印字するまでに 1 [μs] のチャージ時間が必要です。 印字機が印字をする商品とタイミングをうまく選んだとき、最大で何個の商品に印字することができますか?
制約
- 1\leq N \leq 2\times 10^5
- 1\leq T_i,D_i \leq 10^{18}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N T_1 D_1 T_2 D_2 \vdots T_N D_N
出力
印字機が印字することのできる商品の数の最大値を出力せよ。
入力例 1
5 1 1 1 1 2 1 1 2 1 4
出力例 1
4
以下、今から t [μs] 後のことを単に時刻 t とよびます。
例えば、次のようにして 4 個の商品に印字することができます。
- 時刻 1 : 商品 1,2,4,5 が印字機の範囲に入る。商品 4 に印字する。
- 時刻 2 : 商品 3 が印字機の範囲に入り、商品 1,2 が印字機の範囲から出る。商品 1 に印字する。
- 時刻 3 : 商品 3,4 が印字機の範囲から出る。商品 3 に印字する。
- 時刻 4.5 : 商品 5 に印字する。
- 時刻 5 : 商品 5 が印字機の範囲から出る。
5 個の商品すべてに印字することはできないため、答えは 4 です。
入力例 2
2 1 1 1000000000000000000 1000000000000000000
出力例 2
2
入力例 3
10 4 1 1 2 1 4 3 2 5 1 5 1 4 1 2 1 4 1 2 4
出力例 3
6
Score : 450 points
Problem Statement
There are N products labeled 1 to N flowing on a conveyor belt. A Keyence printer is attached to the conveyor belt, and product i enters the range of the printer T_i microseconds from now and leaves it D_i microseconds later.
The Keyence printer can instantly print on one product within the range of the printer (in particular, it is possible to print at the moment the product enters or leaves the range of the printer). However, after printing once, it requires a charge time of 1 microseconds before it can print again. What is the maximum number of products the printer can print on when the product and timing for the printer to print are chosen optimally?
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq T_i,D_i \leq 10^{18}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T_1 D_1 T_2 D_2 \vdots T_N D_N
Output
Print the maximum number of products the printer can print on.
Sample Input 1
5 1 1 1 1 2 1 1 2 1 4
Sample Output 1
4
Below, we will simply call the moment t microseconds from now time t.
For example, you can print on four products as follows:
- Time 1 : Products 1,2,4,5 enter the range of the printer. Print on product 4.
- Time 2 : Product 3 enters the range of the printer, and products 1,2 leave the range of the printer. Print on product 1.
- Time 3 : Products 3,4 leave the range of the printer. Print on product 3.
- Time 4.5 : Print on product 5.
- Time 5 : Product 5 leaves the range of the printer.
It is impossible to print on all five products, so the answer is 4.
Sample Input 2
2 1 1 1000000000000000000 1000000000000000000
Sample Output 2
2
Sample Input 3
10 4 1 1 2 1 4 3 2 5 1 5 1 4 1 2 1 4 1 2 4
Sample Output 3
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
N 頂点 M 辺の単純連結無向グラフ G が与えられます。
G の頂点および辺はそれぞれ頂点 1,2,\ldots,N、辺 1,2,\ldots,M と番号づけられており、
辺 i は頂点 U_i と頂点 V_i を結んでいます。
辺で結ばれている頂点の間は双方向に時間 1 で移動することができます。
また、各頂点は安全か危険かのどちらかであり、その状態は S と D のみからなる長さ N の文字列 S によって与えられます。
具体的には、S の i 文字目 (1\leq i\leq N) が S のとき頂点 i は安全であり、D のとき頂点 i は危険です。
ここで、安全な頂点が 2 つ以上、危険な頂点が 1 つ以上あることが保証されます。
危険な頂点 v それぞれについて、次の値を求めてください。
ある安全な頂点から出発し、v を経由し、 出発した頂点と異なる 安全な頂点へ移動するのにかかる時間としてあり得る最小値
制約
- 3\leq N\leq 2\times 10^5
- N-1\leq M\leq 2\times 10^5
- 1\leq U_i,V_i\leq N
- U_i\neq V_i
- i\neq j ならば \{ U_i,V_i \}\neq \{ U_j,V_j \}
- S は
SとDのみからなる長さ N の文字列 - N,M,U_i,V_i はすべて整数
- G は連結である。
- 安全な頂点が 2 つ以上存在する。
- 危険な頂点が 1 つ以上存在する。
入力
入力は以下の形式で標準入力から与えられる。
N M U_1 V_1 U_2 V_2 \vdots U_M V_M S
出力
G 上の危険な頂点の個数を K として、K 行出力せよ。
i 行目 (1\leq i\leq K) には、危険な頂点を頂点番号の昇順に並べた時に i 番目に来る頂点についての答えを出力せよ。
入力例 1
5 5 1 2 1 3 2 3 3 4 4 5 SSDDS
出力例 1
2 3
危険な頂点は(頂点番号について昇順に)頂点 3 と 4 です。
頂点 3 については、頂点 1 \to 頂点 3 \to 頂点 2 と移動するときなどが条件をみたします。
この移動にかかる時間は 2 であり、このときが最小です。
よって、1 行目に 2 を出力します。
頂点 4 については、頂点 1 \to 頂点 3 \to 頂点 4 \to 頂点 5 と移動するときなどが条件をみたします。
この移動にかかる時間は 3 であり、かかる時間が 2 以下の条件をみたす移動方法がないため、このときが最小です。
よって、2 行目に 3 を出力します。
入力例 2
3 2 1 2 2 3 SSD
出力例 2
3
危険な頂点は頂点 3 です。
頂点 1 \to 頂点 2 \to 頂点 3 \to 頂点 2 と移動するときなどが条件をみたします。
この移動にかかる時間は 3 であり、このときが最小です。
頂点 2 \to 頂点 3 \to 頂点 2 などの移動は、「出発した頂点と異なる」という条件をみたしていないことに注意してください。
Score : 450 points
Problem Statement
You are given a simple connected undirected graph G with N vertices and M edges.
The vertices and edges of G are numbered as vertices 1,2,\ldots,N and edges 1,2,\ldots,M, respectively,
and edge i connects vertices U_i and V_i.
You can move bidirectionally between vertices connected by an edge in time 1.
Additionally, each vertex is either safe or dangerous, and this state is given by a string S of length N consisting of S and D.
Specifically, vertex i is safe when the i-th character (1\leq i\leq N) of S is S, and vertex i is dangerous when it is D.
It is guaranteed that there are at least two safe vertices and at least one dangerous vertex.
For each dangerous vertex v, find the following value:
The minimum possible time to start from some safe vertex, pass through v, and move to a safe vertex different from the starting vertex.
Constraints
- 3\leq N\leq 2\times 10^5
- N-1\leq M\leq 2\times 10^5
- 1\leq U_i,V_i\leq N
- U_i\neq V_i
- If i\neq j, then \{ U_i,V_i \}\neq \{ U_j,V_j \}.
- S is a string of length N consisting of
SandD. - N,M,U_i,V_i are all integers.
- G is connected.
- There are at least two safe vertices.
- There is at least one dangerous vertex.
Input
The input is given from Standard Input in the following format:
N M U_1 V_1 U_2 V_2 \vdots U_M V_M S
Output
Let K be the number of dangerous vertices in G, and print K lines.
On the i-th line (1\leq i\leq K), print the answer for the i-th dangerous vertex when the dangerous vertices are arranged in ascending order of vertex number.
Sample Input 1
5 5 1 2 1 3 2 3 3 4 4 5 SSDDS
Sample Output 1
2 3
The dangerous vertices are (in ascending order of vertex number) vertices 3 and 4.
For vertex 3, moving from vertex 1 \to vertex 3 \to vertex 2 (for example) satisfies the condition.
The time required for this movement is 2, and this is the minimum.
Therefore, print 2 on the 1st line.
For vertex 4, moving from vertex 1 \to vertex 3 \to vertex 4 \to vertex 5 (for example) satisfies the condition.
The time required for this movement is 3, and there is no way to move that satisfies the condition with time 2 or less, so this is the minimum.
Therefore, print 3 on the 2nd line.
Sample Input 2
3 2 1 2 2 3 SSD
Sample Output 2
3
The dangerous vertex is vertex 3.
Moving from vertex 1 \to vertex 2 \to vertex 3 \to vertex 2 (for example) satisfies the condition.
The time required for this movement is 3, and this is the minimum.
Note that movements such as vertex 2 \to vertex 3 \to vertex 2 do not satisfy the condition that the destination is "different from the starting vertex".
実行時間制限: 3.5 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
あなたの前に体力 H のモンスターが現れ、ターン制の戦闘が開始しました。
あなたは、ターン 1,2,… のそれぞれに呪文 1,…,N の N 種類の呪文のうち一つを唱えます。
ターン i に呪文 j を唱えると、その呪文の効果としてターン i,i+1,…,i+t_j -1 のそれぞれでモンスターの体力が d_j 減ります。
モンスターの体力を 0 以下にすることが可能な最も早いターンを求めてください。
制約
- 1 \leq N \leq 3 \times 10^5
- 1 \leq H \leq 10^{18}
- 1 \leq t_i,d_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N H t_1 d_1 \vdots t_N d_N
出力
答えを出力せよ。
入力例 1
2 20 2 2 5 1
出力例 1
6
以下のようにするとターン 6 にモンスターの体力を 0 以下に出来ます。これが最も早いターンです。
- ターン 1 に魔法 1 を使う。ターン 1 に使った魔法の効果でモンスターの体力が 2 減り、18 になる。
- ターン 2 に魔法 2 を使う。ターン 1,2 に使った魔法の効果でモンスターの体力が 2+1=3 減り、15 になる。
- ターン 3 に魔法 1 を使う。ターン 2,3 に使った魔法の効果でモンスターの体力が 1+2=3 減り、12 になる。
- ターン 4 に魔法 2 を使う。ターン 2,3,4 に使った魔法の効果でモンスターの体力が 1+2+1=4 減り、8 になる。
- ターン 5 に魔法 1 を使う。ターン 2,4,5 に使った魔法の効果でモンスターの体力が 1+1+2=4 減り、4 になる。
- ターン 6 に魔法 2 を使う。ターン 2,4,5,6 に使った魔法の効果でモンスターの体力が 1+1+2+1=5 減り、-1 になる。
入力例 2
10 200 1 21 1 1 1 1 8 4 30 1 3 1 10 2 8 1 9 1 4 4
出力例 2
9
Score : 525 points
Problem Statement
A monster with health H has appeared in front of you, and a turn-based battle has started.
In each turn 1,2,…, you cast one of N spells, spells 1,…,N.
If you cast spell i in turn j, the monster's health reduces by d_i in each turn j,j+1,…,j+t_i -1.
Find the earliest turn that you can make the monster's health 0 or less.
Constraints
- 1 \leq N \leq 3 \times 10^5
- 1 \leq H \leq 10^{18}
- 1 \leq t_i,d_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N H t_1 d_1 \vdots t_N d_N
Output
Print the answer.
Sample Input 1
2 20 2 2 5 1
Sample Output 1
6
The following procedure makes the monster's health 0 or less in turn 6, which is the earliest.
- Cast spell 1 in turn 1. Due to the spell cast in turn 1, the monster's health reduces by 2 and becomes 18.
- Cast spell 2 in turn 2. Due to the spells cast in turns 1 and 2, the monster's health reduces by 2+1=3 and becomes 15.
- Cast spell 1 in turn 3. Due to the spells cast in turns 2 and 3, the monster's health reduces by 1+2=3 and becomes 12.
- Cast spell 2 in turn 4. Due to the spells cast in turns 2,3 and 4, the monster's health reduces by 1+2+1=4 and becomes 8.
- Cast spell 1 in turn 5. Due to the spells cast in turns 2,4 and 5, the monster's health reduces by 1+1+2=4 and becomes 4.
- Cast spell 2 in turn 6. Due to the spells cast in turns 2,4,5 and 6, the monster's health reduces by 1+1+2+1=5 and becomes -1.
Sample Input 2
10 200 1 21 1 1 1 1 8 4 30 1 3 1 10 2 8 1 9 1 4 4
Sample Output 2
9