実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 233 点
問題文
高橋君は図書館で本棚の整理をするアルバイトをしています。
本棚には N 冊の本を一列に並べる必要があります。各本には 1 から N の固有の番号が付けられており、本 i の厚さは D_i センチメートルです。
本棚の左端にはブックエンド(幅 S センチメートル)が固定されています。N 冊の本はすべて、このブックエンドの右側に左から右へ一列に並べます。本棚の右端には制限はなく、十分な長さがあるものとします。
図書館の規則では、本の傷みを防ぐため、隣り合う本同士の間には少なくとも K センチメートルの間隔を空ける必要があります。また、ブックエンドと最も左の本との間にも K センチメートル以上の間隔を空ける必要があります。ここで、2つの物の間の間隔とは、左側の物の右端から右側の物の左端までの距離を指します。
高橋君は、N 冊の本すべてをちょうど1回ずつ、好きな順番で並べることができます。すべての本を並べ終えたとき、ブックエンドの左端から最も右の本の右端までの距離の最小値を求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq S \leq 10^9
- 1 \leq K \leq 10^9
- 1 \leq D_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
N S K D_1 D_2 \cdots D_N
- 1 行目には、本の冊数を表す整数 N 、ブックエンドの幅を表す整数 S 、必要な最小間隔を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各本の厚さを表す整数 D_1, D_2, \ldots, D_N が、スペース区切りで与えられる。
出力
ブックエンドの左端から最も右の本の右端までの距離の最小値を整数で 1 行に出力してください。
入力例 1
3 2 1 3 1 2
出力例 1
11
入力例 2
1 5 3 4
出力例 2
12
入力例 3
5 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 3
11000000000
Score : 233 pts
Problem Statement
Takahashi has a part-time job organizing bookshelves at a library.
He needs to arrange N books in a row on a bookshelf. Each book has a unique number from 1 to N, and book i has a thickness of D_i centimeters.
A bookend (with width S centimeters) is fixed at the left end of the bookshelf. All N books are to be placed in a row from left to right, to the right of this bookend. There is no restriction on the right end of the bookshelf, and it can be assumed to be sufficiently long.
According to the library's rules, to prevent damage to the books, there must be a gap of at least K centimeters between any two adjacent books. Additionally, there must be a gap of at least K centimeters between the bookend and the leftmost book. Here, the gap between two objects refers to the distance from the right edge of the left object to the left edge of the right object.
Takahashi can arrange all N books exactly once each, in any order he likes. After all books have been placed, find the minimum possible distance from the left edge of the bookend to the right edge of the rightmost book.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq S \leq 10^9
- 1 \leq K \leq 10^9
- 1 \leq D_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers
Input
N S K D_1 D_2 \cdots D_N
- The first line contains three space-separated integers: N representing the number of books, S representing the width of the bookend, and K representing the required minimum gap.
- The second line contains space-separated integers D_1, D_2, \ldots, D_N representing the thickness of each book.
Output
Print the minimum possible distance from the left edge of the bookend to the right edge of the rightmost book as an integer on a single line.
Sample Input 1
3 2 1 3 1 2
Sample Output 1
11
Sample Input 2
1 5 3 4
Sample Output 2
12
Sample Input 3
5 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
11000000000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 333 点
問題文
高橋君は、文字列を整理する作業をしています。
高橋君は、文字列に対して次の操作を 0 回以上繰り返し行うことができます。
- 文字列の中から、隣り合う同じ文字 2 文字(例えば
aaやbb)を 1 組選び、その 2 文字を文字列から取り除く。取り除いた後、残った左右の部分はそのまま連結される。
例えば、文字列 abba に対して、隣り合う bb を取り除くと aa になり、さらに aa を取り除くと空文字列になります。
英小文字からなる文字列 S が与えられるので、操作を繰り返した後に得られる文字列の長さの最小値を求めてください。
制約
- 1 \leq |S| \leq 10^6(|S| は文字列 S の長さを表す)
- S は英小文字からなる文字列である。
入力
S
文字列 S が 1 行で与えられる。
出力
操作を最適に繰り返した後に得られる文字列の長さの最小値を 1 行で出力せよ。
入力例 1
abba
出力例 1
0
入力例 2
abcde
出力例 2
5
入力例 3
abbacaaccbbddeeffeedcba
出力例 3
5
入力例 4
aaabccddddeeffffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz
出力例 4
22
入力例 5
a
出力例 5
1
Score : 333 pts
Problem Statement
Takahashi is working on organizing strings.
Takahashi can perform the following operation on a string zero or more times:
- Choose one pair of adjacent identical characters (for example,
aaorbb) in the string, and remove those 2 characters from the string. After removal, the remaining left and right parts are concatenated as they are.
For example, given the string abba, removing the adjacent bb yields aa, and further removing aa yields the empty string.
You are given a string S consisting of lowercase English letters. Find the minimum possible length of the string obtained after performing the operation repeatedly.
Constraints
- 1 \leq |S| \leq 10^6 (|S| denotes the length of string S)
- S is a string consisting of lowercase English letters.
Input
S
The string S is given on a single line.
Output
Print the minimum possible length of the string obtained after optimally repeating the operation, on a single line.
Sample Input 1
abba
Sample Output 1
0
Sample Input 2
abcde
Sample Output 2
5
Sample Input 3
abbacaaccbbddeeffeedcba
Sample Output 3
5
Sample Input 4
aaabccddddeeffffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz
Sample Output 4
22
Sample Input 5
a
Sample Output 5
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は、N 人の顧客の会員登録を管理するシステムを運営しています。
それぞれの顧客には 1 から N までの番号が付けられており、顧客 i は優先度 A_i を持っています。すべての顧客の優先度は互いに異なります。優先度の値が大きいほど、優先度が高いものとします。
ショップは M 店舗あり、各ショップには 1 から M までの番号が付けられています。ショップ j には会員枠 C_j が設定されており、そのショップに同時に登録できる会員数の上限を表しています。
はじめ、どの顧客もどのショップにも登録されていません。これから Q 件の申請が順番に処理されます。各顧客が申請を行うのは高々 1 回です(すなわち、異なる申請の申請者はすべて異なります)。k 番目の申請では、顧客 P_k がショップ D_k への会員登録を希望します。
申請が処理されるとき、以下のルールに従います:
- そのショップの現在の会員数が会員枠 C_{D_k} 未満であれば、顧客 P_k はそのショップの会員として登録されます。
- そのショップの現在の会員数が会員枠 C_{D_k} に等しい(すなわち満員である)場合、現在そのショップに登録されている会員の中で最も優先度が低い会員と、申請した顧客 P_k の優先度を比較します。すべての顧客の優先度は互いに異なるため、最も優先度が低い会員は一意に定まります。
- 申請した顧客の優先度の方が高ければ、最も優先度が低い会員の登録は解除され(どのショップにも登録されていない状態に戻ります)、申請した顧客が新たにそのショップの会員として登録されます。
- そうでなければ(申請した顧客の優先度の方が低ければ)、申請は却下されます。申請した顧客はどのショップにも登録されていない状態のままであり、ショップの会員にも変化はありません。
上記のルールにより、どの時点においても各ショップの会員数は会員枠を超えません。また、各顧客が申請を行うのは高々 1 回であるため、ある顧客が複数のショップに同時に登録されることはありません。
すべての申請の処理が完了した後、各ショップに登録されている会員の人数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- A_i \neq A_j (i \neq j)
- 1 \leq C_j \leq N (1 \leq j \leq M)
- 1 \leq P_k \leq N (1 \leq k \leq Q)
- 1 \leq D_k \leq M (1 \leq k \leq Q)
- P_k \neq P_l (k \neq l)(すなわち、各顧客が申請を行うのは高々 1 回である)
- 入力はすべて整数
入力
N M Q A_1 A_2 \ldots A_N C_1 C_2 \ldots C_M P_1 D_1 P_2 D_2 \vdots P_Q D_Q
- 1 行目には、顧客の人数 N 、ショップの数 M 、申請の件数 Q が、スペース区切りで与えられる。
- 2 行目には、各顧客の優先度 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
- 3 行目には、各ショップの会員枠 C_1, C_2, \ldots, C_M が、スペース区切りで与えられる。
- 続く Q 行では、各申請の情報が与えられる。
- 3 + k 行目には、k 番目の申請を行う顧客の番号 P_k と、希望するショップの番号 D_k がスペース区切りで与えられる。
出力
M 個の整数をスペース区切りで 1 行に出力せよ。 j 番目の整数は、ショップ j に最終的に登録されている会員の人数を表す。
入力例 1
5 2 5 10 30 20 50 40 2 1 1 1 2 1 3 1 4 2 5 2
出力例 1
2 1
入力例 2
7 3 7 5 15 25 35 45 55 3 2 2 1 7 1 1 1 3 1 2 2 4 2 5 2 6 3
出力例 2
2 2 1
入力例 3
10 4 10 100 90 80 70 60 50 40 30 20 10 3 2 2 1 8 1 10 1 9 1 7 1 5 2 6 2 3 2 4 3 2 3 1 4
出力例 3
3 2 2 1
Score : 366 pts
Problem Statement
Takahashi operates a system that manages membership registration for N customers.
Each customer is assigned a number from 1 to N, and customer i has a priority A_i. All customers have distinct priorities. A larger priority value means a higher priority.
There are M shops, each numbered from 1 to M. Shop j has a membership capacity C_j, which represents the maximum number of members that can be registered at that shop simultaneously.
Initially, no customer is registered at any shop. From now on, Q applications will be processed in order. Each customer submits at most one application (that is, all applicants across different applications are distinct). In the k-th application, customer P_k requests membership registration at shop D_k.
When an application is processed, the following rules apply:
- If the current number of members at the shop is less than the capacity C_{D_k}, customer P_k is registered as a member of that shop.
- If the current number of members at the shop equals the capacity C_{D_k} (i.e., the shop is full), the priority of the applying customer P_k is compared with that of the member currently registered at the shop who has the lowest priority. Since all customers have distinct priorities, the member with the lowest priority is uniquely determined.
- If the applying customer's priority is higher, the member with the lowest priority is unregistered (returning to a state of not being registered at any shop), and the applying customer is newly registered as a member of that shop.
- Otherwise (if the applying customer's priority is lower), the application is rejected. The applying customer remains unregistered at any shop, and the shop's members remain unchanged.
By the above rules, the number of members at each shop never exceeds its capacity at any point. Also, since each customer submits at most one application, no customer is ever registered at multiple shops simultaneously.
After all applications have been processed, determine the number of members registered at each shop.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- A_i \neq A_j (i \neq j)
- 1 \leq C_j \leq N (1 \leq j \leq M)
- 1 \leq P_k \leq N (1 \leq k \leq Q)
- 1 \leq D_k \leq M (1 \leq k \leq Q)
- P_k \neq P_l (k \neq l) (that is, each customer submits at most one application)
- All input values are integers
Input
N M Q A_1 A_2 \ldots A_N C_1 C_2 \ldots C_M P_1 D_1 P_2 D_2 \vdots P_Q D_Q
- The first line contains the number of customers N, the number of shops M, and the number of applications Q, separated by spaces.
- The second line contains the priorities A_1, A_2, \ldots, A_N of each customer, separated by spaces.
- The third line contains the membership capacities C_1, C_2, \ldots, C_M of each shop, separated by spaces.
- The following Q lines contain information about each application.
- The (3 + k)-th line contains the customer number P_k who submits the k-th application and the desired shop number D_k, separated by a space.
Output
Output M integers separated by spaces on a single line. The j-th integer represents the number of members finally registered at shop j.
Sample Input 1
5 2 5 10 30 20 50 40 2 1 1 1 2 1 3 1 4 2 5 2
Sample Output 1
2 1
Sample Input 2
7 3 7 5 15 25 35 45 55 3 2 2 1 7 1 1 1 3 1 2 2 4 2 5 2 6 3
Sample Output 2
2 2 1
Sample Input 3
10 4 10 100 90 80 70 60 50 40 30 20 10 3 2 2 1 8 1 10 1 9 1 7 1 5 2 6 2 3 2 4 3 2 3 1 4
Sample Output 3
3 2 2 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は宝石店を経営しています。今度開催される宝石展示会に出品する宝石を選ぼうとしています。
店には N 種類の宝石があり、それぞれの宝石 i には価値 B_i と重さ W_i が設定されています。展示会場に持ち込める宝石の総重量には上限 C があり、それを超える重さの宝石を持ち込むことはできません。
高橋君は特殊な軽量化ケースを K 個持っています。この軽量化ケースを使うと、1個につき1種類の宝石の重さを半分(小数点以下切り捨て)にすることができます。ただし、同じ宝石に複数個のケースを使うことはできません。
高橋君は各種類の宝石を最大1つずつ持ち込むことができます。持ち込む宝石の価値の合計を最大化したいと考えています。
軽量化ケースを最適に使ったとき、持ち込むことができる宝石の価値の合計の最大値を求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq C \leq 10^5
- 0 \leq K \leq \min(N, 30)
- N(K+1)(C+1) \leq 2 \times 10^7
- 1 \leq B_i \leq 10^9
- 1 \leq W_i \leq 2C
- 入力はすべて整数である
入力
N C K B_1 W_1 B_2 W_2 : B_N W_N
- 1 行目には、宝石の種類数を表す N 、重量の上限を表す C 、軽量化ケースの個数を表す K が、スペース区切りで与えられる。
- 2 行目から N + 1 行目では、各宝石の情報が与えられる。
- 1 + i 行目では、宝石 i の価値 B_i と重さ W_i が、スペース区切りで与えられる。
出力
持ち込むことができる宝石の価値の合計の最大値を 1 行で出力してください。
入力例 1
4 10 1 8 6 10 7 5 4 6 5
出力例 1
18
入力例 2
5 12 0 7 3 12 8 9 5 4 6 11 10
出力例 2
19
入力例 3
12 50 3 30 18 45 27 25 15 60 40 35 22 50 35 20 12 55 45 40 30 15 10 70 55 28 16
出力例 3
155
入力例 4
40 300 6 120 80 250 180 90 60 310 240 180 130 400 350 75 45 220 170 500 420 160 110 330 260 140 90 270 200 600 500 95 70 210 160 450 380 125 85 360 290 280 210 510 460 170 125 390 310 240 190 700 590 155 100 430 330 105 75 320 250 260 205 540 440 190 140 470 360 115 95 350 270 290 230 620 520 200 150 410 340 130 105
出力例 4
885
入力例 5
1 1 1 1000000000 2
出力例 5
1000000000
Score : 400 pts
Problem Statement
Takahashi runs a jewelry store. He is trying to select jewels to exhibit at an upcoming jewelry exhibition.
The store has N types of jewels, and each jewel i has a value B_i and a weight W_i. There is an upper limit C on the total weight of jewels that can be brought to the exhibition venue, and jewels exceeding this weight cannot be brought in.
Takahashi has K special weight-reduction cases. By using one weight-reduction case, he can halve the weight of one type of jewel (rounded down to the nearest integer). However, multiple cases cannot be used on the same jewel.
Takahashi can bring at most one jewel of each type. He wants to maximize the total value of the jewels he brings.
Find the maximum total value of jewels that can be brought when the weight-reduction cases are used optimally.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq C \leq 10^5
- 0 \leq K \leq \min(N, 30)
- N(K+1)(C+1) \leq 2 \times 10^7
- 1 \leq B_i \leq 10^9
- 1 \leq W_i \leq 2C
- All inputs are integers
Input
N C K B_1 W_1 B_2 W_2 : B_N W_N
- The first line contains N representing the number of types of jewels, C representing the weight limit, and K representing the number of weight-reduction cases, separated by spaces.
- From the 2nd line to the (N + 1)-th line, the information of each jewel is given.
- The (1 + i)-th line contains the value B_i and weight W_i of jewel i, separated by spaces.
Output
Print the maximum total value of jewels that can be brought in a single line.
Sample Input 1
4 10 1 8 6 10 7 5 4 6 5
Sample Output 1
18
Sample Input 2
5 12 0 7 3 12 8 9 5 4 6 11 10
Sample Output 2
19
Sample Input 3
12 50 3 30 18 45 27 25 15 60 40 35 22 50 35 20 12 55 45 40 30 15 10 70 55 28 16
Sample Output 3
155
Sample Input 4
40 300 6 120 80 250 180 90 60 310 240 180 130 400 350 75 45 220 170 500 420 160 110 330 260 140 90 270 200 600 500 95 70 210 160 450 380 125 85 360 290 280 210 510 460 170 125 390 310 240 190 700 590 155 100 430 330 105 75 320 250 260 205 540 440 190 140 470 360 115 95 350 270 290 230 620 520 200 150 410 340 130 105
Sample Output 4
885
Sample Input 5
1 1 1 1000000000 2
Sample Output 5
1000000000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 466 点
問題文
高橋君は N 個のタスクを順番に処理する仕事をしています。
i 番目のタスクには、負荷を表す整数 A_i と、休憩による回復量を表す整数 B_i が定められています。
高橋君のストレス値を非負整数 G(初期値 0)で、限界に達した回数を非負整数 C(初期値 0)で管理します。タスク i を処理するとき、次の操作をステップ 1, 2, 3 の順に行います。
- タスクの負荷により、ストレス値が A_i だけ増えます。すなわち、G を G + A_i に更新します。
- タスク後の休憩により、ストレス値が B_i だけ減ります。ただし、ストレス値は 0 未満にはなりません。すなわち、G を \max(0, G - B_i) に更新します。
- この時点で G \geq K ならば、高橋君は限界に達します。C を C + 1 に更新し、G を 0 に更新します。G < K ならば何もしません。
ステップ 3 の処理が終わった後(限界に達した場合も達しなかった場合も)、次のタスクの処理に進みます。
青木君は、「タスク列の一部分だけを処理したらどうなるか」を Q 回質問します。
j 番目の質問では、整数 L_j と R_j が与えられます。
G = 0, C = 0 から開始し、タスク L_j, L_j + 1, \ldots, R_j をこの順に処理したとき、すべてのタスクの処理(ステップ 3 まで)を終えた後の限界に達した回数 C とストレス値 G を求めてください。
各質問は独立です。ある質問の結果が別の質問に影響することはありません。
制約
- 1 \leq N \leq 6 \times 10^4
- 1 \leq K \leq 300
- 1 \leq Q \leq 6 \times 10^4
- 1 \leq A_i \leq 10^9
- 0 \leq B_i \leq 10^9
- 1 \leq L_j \leq R_j \leq N
- 入力はすべて整数である。
入力
N K Q A_1 B_1 A_2 B_2 \vdots A_N B_N L_1 R_1 L_2 R_2 \vdots L_Q R_Q
- 1 行目には、タスクの個数 N、限界のしきい値 K、質問の個数 Q が、スペース区切りで与えられる。
- 続く N 行のうち i 行目には、i 番目のタスクの負荷 A_i と休憩による回復量 B_i が、スペース区切りで与えられる。
- 続く Q 行のうち j 行目には、j 番目の質問で処理する区間の左端 L_j と右端 R_j が、スペース区切りで与えられる。
出力
Q 行出力せよ。j 行目には、j 番目の質問に対する限界に達した回数 C とストレス値 G を、この順にスペース区切りで出力せよ。
入力例 1
5 10 4 6 2 4 1 8 0 3 5 10 3 1 3 2 4 4 5 3 3
出力例 1
1 0 1 0 0 7 0 8
入力例 2
4 5 5 1 0 2 5 5 0 6 2 1 1 1 2 1 3 3 4 4 4
出力例 2
0 1 0 0 1 0 1 4 0 4
入力例 3
15 20 10 7 3 12 5 4 10 25 0 3 1 18 4 6 6 30 15 9 0 2 8 14 2 5 20 21 1 8 7 11 0 1 5 2 8 4 4 6 10 1 15 9 15 11 13 3 12 7 14 10 10
出力例 3
1 2 2 0 1 0 1 3 3 12 1 12 1 0 2 0 2 1 0 0
入力例 4
40 300 25 120 30 250 100 80 0 500 250 40 60 1000 800 299 0 1 0 600 350 75 75 310 10 20 5 450 200 90 10 200 50 150 200 700 401 60 0 30 100 1000000000 999999900 5 0 295 10 400 120 55 55 180 30 240 100 360 80 15 0 90 20 600 600 280 0 35 10 100 0 500 260 70 30 330 40 10 100 220 10 410 200 50 0 1 10 5 15 10 20 15 25 20 30 25 35 30 40 1 40 7 7 11 18 19 22 23 29 31 36 34 40 2 39 4 13 8 27 12 32 16 16 20 20 21 40 1 1 40 40 6 24 14 38
出力例 4
3 250 3 150 3 100 3 0 3 85 3 40 4 50 13 50 0 299 3 60 1 0 2 85 3 0 2 50 12 0 3 265 6 0 6 25 0 0 0 100 6 50 0 90 0 50 5 280 7 210
入力例 5
1 300 1 1000000000 999999700 1 1
出力例 5
1 0
Score : 466 pts
Problem Statement
Takahashi has a job where he processes N tasks in order.
For the i-th task, an integer A_i representing the workload and an integer B_i representing the recovery from a break are defined.
Takahashi's stress level is managed as a non-negative integer G (initially 0), and the number of times he has reached his limit is managed as a non-negative integer C (initially 0). When processing task i, the following operations are performed in order of steps 1, 2, 3.
- Due to the task's workload, the stress level increases by A_i. That is, G is updated to G + A_i.
- Due to the break after the task, the stress level decreases by B_i. However, the stress level does not go below 0. That is, G is updated to \max(0, G - B_i).
- At this point, if G \geq K, Takahashi reaches his limit. C is updated to C + 1, and G is updated to 0. If G < K, nothing happens.
After step 3 is completed (whether or not he reached his limit), he proceeds to process the next task.
Aoki asks Q questions of the form "What would happen if only a portion of the task sequence were processed?"
In the j-th question, integers L_j and R_j are given.
Starting from G = 0, C = 0, determine the number of times the limit was reached C and the stress level G after all tasks L_j, L_j + 1, \ldots, R_j have been processed (through step 3) in this order.
Each question is independent. The result of one question does not affect another question.
Constraints
- 1 \leq N \leq 6 \times 10^4
- 1 \leq K \leq 300
- 1 \leq Q \leq 6 \times 10^4
- 1 \leq A_i \leq 10^9
- 0 \leq B_i \leq 10^9
- 1 \leq L_j \leq R_j \leq N
- All inputs are integers.
Input
N K Q A_1 B_1 A_2 B_2 \vdots A_N B_N L_1 R_1 L_2 R_2 \vdots L_Q R_Q
- The first line contains the number of tasks N, the limit threshold K, and the number of questions Q, separated by spaces.
- In the following N lines, the i-th line contains the workload A_i and the recovery from a break B_i for the i-th task, separated by spaces.
- In the following Q lines, the j-th line contains the left endpoint L_j and right endpoint R_j of the interval to be processed in the j-th question, separated by spaces.
Output
Output Q lines. The j-th line should contain the number of times the limit was reached C and the stress level G for the j-th question, in this order, separated by a space.
Sample Input 1
5 10 4 6 2 4 1 8 0 3 5 10 3 1 3 2 4 4 5 3 3
Sample Output 1
1 0 1 0 0 7 0 8
Sample Input 2
4 5 5 1 0 2 5 5 0 6 2 1 1 1 2 1 3 3 4 4 4
Sample Output 2
0 1 0 0 1 0 1 4 0 4
Sample Input 3
15 20 10 7 3 12 5 4 10 25 0 3 1 18 4 6 6 30 15 9 0 2 8 14 2 5 20 21 1 8 7 11 0 1 5 2 8 4 4 6 10 1 15 9 15 11 13 3 12 7 14 10 10
Sample Output 3
1 2 2 0 1 0 1 3 3 12 1 12 1 0 2 0 2 1 0 0
Sample Input 4
40 300 25 120 30 250 100 80 0 500 250 40 60 1000 800 299 0 1 0 600 350 75 75 310 10 20 5 450 200 90 10 200 50 150 200 700 401 60 0 30 100 1000000000 999999900 5 0 295 10 400 120 55 55 180 30 240 100 360 80 15 0 90 20 600 600 280 0 35 10 100 0 500 260 70 30 330 40 10 100 220 10 410 200 50 0 1 10 5 15 10 20 15 25 20 30 25 35 30 40 1 40 7 7 11 18 19 22 23 29 31 36 34 40 2 39 4 13 8 27 12 32 16 16 20 20 21 40 1 1 40 40 6 24 14 38
Sample Output 4
3 250 3 150 3 100 3 0 3 85 3 40 4 50 13 50 0 299 3 60 1 0 2 85 3 0 2 50 12 0 3 265 6 0 6 25 0 0 0 100 6 50 0 90 0 50 5 280 7 210
Sample Input 5
1 300 1 1000000000 999999700 1 1
Sample Output 5
1 0