Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は運送会社で働いています。今日は N 台のトラックにそれぞれ荷物を積み込む作業を担当しています。
トラック i (1 \leq i \leq N) に積み込む荷物は、1 個あたりの重さがすべて等しく P_i キログラムです。高橋君はこの荷物を 1 個ずつ積み込んでいきます。
各トラックの積載上限は共通で T キログラムです。トラック i に荷物を k 個積み込むとき、荷物の合計重量が T キログラムを超えてはいけません。すなわち、P_i \times k \leq T が成り立つ必要があります。
さらに、各トラックに積み込める荷物の個数には共通の上限 R 個が設けられています。積載上限に達していなくても、R 個を積み込んだ時点でそのトラックへの積み込みは終了します。
各トラック i について、積載上限と個数上限の両方を満たす範囲で積み込める荷物の最大個数 r_i を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq R \leq 10^9
- 1 \leq T \leq 10^{18}
- 1 \leq P_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
N R T P_1 P_2 \ldots P_N
- 1 行目には、トラックの台数を表す整数 N、各トラックに積み込める荷物の個数の上限を表す整数 R、積載上限を表す整数 T が、スペース区切りで与えられる。
- 2 行目には、各トラックに積み込む荷物 1 個あたりの重さを表す整数 P_1, P_2, \ldots, P_N が、スペース区切りで与えられる。
出力
N 個の整数 r_1, r_2, \ldots, r_N をスペース区切りで 1 行で出力せよ。ここで r_i はトラック i に積み込める荷物の最大個数である。
入力例 1
3 5 20 3 5 7
出力例 1
5 4 2
入力例 2
4 10 15 1 4 8 16
出力例 2
10 3 1 0
入力例 3
10 100 1000 1 2 5 10 50 100 200 333 500 1001
出力例 3
100 100 100 100 20 10 5 3 2 0
入力例 4
20 1000000000 1000000000000000000 1 2 3 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 999999999 500000000 250000000 123456789 777777777 42 314159265 271828182
出力例 4
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
入力例 5
1 1000000000 1 1000000000
出力例 5
0
Score : 200 pts
Problem Statement
Takahashi works at a shipping company. Today, he is in charge of loading cargo onto N trucks.
The items to be loaded onto truck i (1 \leq i \leq N) all have the same weight of P_i kilograms each. Takahashi loads these items one by one.
Every truck has a common weight capacity of T kilograms. When loading k items onto truck i, the total weight of the items must not exceed T kilograms. That is, P_i \times k \leq T must hold.
Furthermore, there is a common upper limit of R items on the number of items that can be loaded onto each truck. Even if the weight capacity has not been reached, loading for that truck ends once R items have been loaded.
For each truck i, determine the maximum number of items r_i that can be loaded while satisfying both the weight capacity and the item count limit.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq R \leq 10^9
- 1 \leq T \leq 10^{18}
- 1 \leq P_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
N R T P_1 P_2 \ldots P_N
- The first line contains an integer N representing the number of trucks, an integer R representing the upper limit on the number of items that can be loaded onto each truck, and an integer T representing the weight capacity, separated by spaces.
- The second line contains integers P_1, P_2, \ldots, P_N representing the weight of one item to be loaded onto each truck, separated by spaces.
Output
Output N integers r_1, r_2, \ldots, r_N separated by spaces on a single line, where r_i is the maximum number of items that can be loaded onto truck i.
Sample Input 1
3 5 20 3 5 7
Sample Output 1
5 4 2
Sample Input 2
4 10 15 1 4 8 16
Sample Output 2
10 3 1 0
Sample Input 3
10 100 1000 1 2 5 10 50 100 200 333 500 1001
Sample Output 3
100 100 100 100 20 10 5 3 2 0
Sample Input 4
20 1000000000 1000000000000000000 1 2 3 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 999999999 500000000 250000000 123456789 777777777 42 314159265 271828182
Sample Output 4
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Input 5
1 1000000000 1 1000000000
Sample Output 5
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君と青木君は、マラソン大会に参加しています。このマラソンコースには N 個のチェックポイントがあり、選手はこれらを 1 番目から N 番目まで順番に通過していきます。
i 番目のチェックポイントから i + 1 番目のチェックポイントまでの距離は D_i メートルです(1 \leq i \leq N-1)。
レース開始時点(時刻 0 秒)で、両者は同時に 1 番目のチェックポイントをスタートしました。
高橋君は休憩をとらず一定のペースで走り続け、1 秒あたり V メートルの速さで進みます。したがって、高橋君が i 番目のチェックポイント(2 \leq i \leq N)に到着する時刻は \displaystyle\frac{D_1 + D_2 + \cdots + D_{i-1}}{V} 秒です。この値は整数とは限りません。
一方、青木君はペースにムラがあり、i 番目のチェックポイントに時刻 T_i 秒ちょうどに到着することがわかっています。ここで T_1 = 0 です。青木君の到着時刻は T_1 < T_2 < T_3 < \cdots < T_N を満たします。
2 番目以降の各チェックポイント i(2 \leq i \leq N)について、高橋君の到着時刻が青木君の到着時刻 T_i より真に小さいとき、すなわち
D_1 + D_2 + \cdots + D_{i-1} < T_i \times V
が成り立つとき、高橋君はチェックポイント i で青木君に先着したといいます。同時に到着した場合は先着には含みません。
高橋君が青木君に先着するチェックポイントの番号をすべて求め、小さい順に出力してください。先着するチェックポイントが一つもない場合は -1 を出力してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq V \leq 10^9
- 1 \leq D_i \leq 10^9 (1 \leq i \leq N-1)
- T_1 = 0
- 1 \leq T_i \leq 10^{18} (2 \leq i \leq N)
- T_i < T_{i+1} (1 \leq i \leq N-1)
- 入力はすべて整数
入力
N V
D_1 D_2 \cdots D_{N-1}
T_2 T_3 \cdots T_N
- 1 行目には、チェックポイントの数 N と、高橋君の速さ V(メートル毎秒)が、スペース区切りで与えられる。
- 2 行目には、i 番目のチェックポイントから i + 1 番目のチェックポイントまでの距離 D_i(メートル)が N - 1 個(i = 1, 2, \ldots, N-1 の順)、スペース区切りで与えられる。
- 3 行目には、青木君が i 番目のチェックポイントに到着する時刻 T_i(秒)が N - 1 個(i = 2, 3, \ldots, N の順)、スペース区切りで与えられる。T_1 = 0 は入力には含まれない。
出力
高橋君が青木君に先着するチェックポイントの番号を、小さい順にスペース区切りで 1 行に出力してください。先着するチェックポイントが一つもない場合は -1 を出力してください。
入力例 1
5 10 30 50 40 60 4 10 15 20
出力例 1
2 3 4 5
入力例 2
4 5 100 100 100 10 20 30
出力例 2
-1
入力例 3
8 100 500 300 700 200 400 600 800 4 8 20 25 35 50 80
出力例 3
4 5 6 7 8
Score : 233 pts
Problem Statement
Takahashi and Aoki are participating in a marathon race. The marathon course has N checkpoints, and runners pass through them in order from the 1-st to the N-th.
The distance from the i-th checkpoint to the (i + 1)-th checkpoint is D_i meters (1 \leq i \leq N-1).
At the start of the race (time 0 seconds), both of them started simultaneously from the 1-st checkpoint.
Takahashi runs at a constant pace without taking any breaks, advancing at a speed of V meters per second. Therefore, the time at which Takahashi arrives at the i-th checkpoint (2 \leq i \leq N) is \displaystyle\frac{D_1 + D_2 + \cdots + D_{i-1}}{V} seconds. This value is not necessarily an integer.
On the other hand, Aoki runs at an uneven pace, and it is known that he arrives at the i-th checkpoint at exactly time T_i seconds. Here, T_1 = 0. Aoki's arrival times satisfy T_1 < T_2 < T_3 < \cdots < T_N.
For each checkpoint i from the 2-nd onward (2 \leq i \leq N), if Takahashi's arrival time is strictly less than Aoki's arrival time T_i, that is, if
D_1 + D_2 + \cdots + D_{i-1} < T_i \times V
holds, then Takahashi is said to have arrived first at checkpoint i ahead of Aoki. If they arrive at the same time, it does not count as arriving first.
Find all checkpoint numbers where Takahashi arrives first ahead of Aoki, and output them in ascending order. If there are no such checkpoints, output -1.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq V \leq 10^9
- 1 \leq D_i \leq 10^9 (1 \leq i \leq N-1)
- T_1 = 0
- 1 \leq T_i \leq 10^{18} (2 \leq i \leq N)
- T_i < T_{i+1} (1 \leq i \leq N-1)
- All input values are integers.
Input
N V
D_1 D_2 \cdots D_{N-1}
T_2 T_3 \cdots T_N
- The first line contains the number of checkpoints N and Takahashi's speed V (meters per second), separated by a space.
- The second line contains N - 1 distances D_i (meters) from the i-th checkpoint to the (i + 1)-th checkpoint (in order of i = 1, 2, \ldots, N-1), separated by spaces.
- The third line contains N - 1 arrival times T_i (seconds) at which Aoki arrives at the i-th checkpoint (in order of i = 2, 3, \ldots, N), separated by spaces. T_1 = 0 is not included in the input.
Output
Output the checkpoint numbers where Takahashi arrives first ahead of Aoki, in ascending order, separated by spaces, on a single line. If there are no such checkpoints, output -1.
Sample Input 1
5 10 30 50 40 60 4 10 15 20
Sample Output 1
2 3 4 5
Sample Input 2
4 5 100 100 100 10 20 30
Sample Output 2
-1
Sample Input 3
8 100 500 300 700 200 400 600 800 4 8 20 25 35 50 80
Sample Output 3
4 5 6 7 8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は、終電に乗るために駅へ向かっています。
高橋君は数直線上の座標 0 にいて、駅は座標 G にあります( G > 0 )。一方、終電は現在座標 M にいて、高橋君のいる方向へ向かって走ってきており、駅に到着した後は発車して去っていきます。
高橋君は通常、毎秒 1 の速度で移動できますが、「全力ダッシュ」をすることで、その秒は速度が D 倍になります。ただし、体力の関係で全力ダッシュは合計で K 秒分しかできません。
終電は毎秒 V の速度で駅に向かって移動しています。終電が駅に到着してから発車するまでの停車時間は一瞬であるため、高橋君が駅に到着するより先に終電が駅を通過してしまうと、高橋君は終電に乗れません。
高橋君が全力ダッシュを最適に使ったとき、終電に間に合うかどうかを判定してください。
なお、高橋君と終電は同時に移動を開始し、高橋君が駅に到達した瞬間以前に終電も駅に到達していれば、高橋君は終電に乗ることができます(同時に到達した場合も乗れます)。
制約
- 1 \leq G \leq 10^9
- G \leq M \leq 10^{15}
- 2 \leq D \leq 10^9
- 0 \leq K \leq 10^9
- 1 \leq V \leq 10^9
- 入力はすべて整数
入力
G M D K V
- 1 行目には、駅の座標 G 、終電の初期座標 M 、全力ダッシュ時の速度倍率 D 、全力ダッシュを使える秒数 K 、終電の速度 V が、スペース区切りで与えられる。
出力
高橋君が終電に間に合う場合は Yes を、間に合わない場合は No を出力せよ。
入力例 1
10 30 3 2 1
出力例 1
Yes
入力例 2
100 120 2 3 10
出力例 2
No
入力例 3
1000000000 1000000000000000 1000000000 1 1
出力例 3
Yes
Score : 300 pts
Problem Statement
Takahashi is heading to the station to catch the last train.
Takahashi is at coordinate 0 on a number line, and the station is at coordinate G (G > 0). Meanwhile, the last train is currently at coordinate M and is heading toward Takahashi's direction, toward the station. After arriving at the station, the train will depart and leave.
Normally, Takahashi can move at a speed of 1 per second, but by performing a "full sprint," his speed becomes D times faster for that second. However, due to stamina limitations, he can only sprint for a total of K seconds.
The last train is moving toward the station at a speed of V per second. Since the stopping time between the train's arrival at the station and its departure is instantaneous, if the last train passes through the station before Takahashi arrives, he cannot board the train.
Determine whether Takahashi can catch the last train if he uses his full sprints optimally.
Note that Takahashi and the last train start moving simultaneously. Takahashi can board the last train if the train has also arrived at the station by the moment Takahashi reaches the station (including the case where they arrive at the same time).
Constraints
- 1 \leq G \leq 10^9
- G \leq M \leq 10^{15}
- 2 \leq D \leq 10^9
- 0 \leq K \leq 10^9
- 1 \leq V \leq 10^9
- All inputs are integers
Input
G M D K V
- The first line contains the station's coordinate G, the last train's initial coordinate M, the speed multiplier during full sprint D, the number of seconds full sprint can be used K, and the last train's speed V, separated by spaces.
Output
If Takahashi can catch the last train, print Yes; otherwise, print No.
Sample Input 1
10 30 3 2 1
Sample Output 1
Yes
Sample Input 2
100 120 2 3 10
Sample Output 2
No
Sample Input 3
1000000000 1000000000000000 1000000000 1 1
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は配送会社でアルバイトをしています。この地域には N 個の配送拠点があり、拠点には 1 から N までの番号が付けられています。
この地域には M 本の道路があり、i 番目の道路は拠点 A_i と拠点 B_i を双方向に結んでいます。この道路を通ると、どちらの方向に進んでも C_i 分の時間がかかります。
高橋君は今日、本社のある拠点 1 を出発し、拠点 T にいる顧客のもとへ荷物を届けてから、拠点 1 に戻らなければなりません。
具体的には、高橋君は拠点 1 から出発して道路を順にたどって移動し、移動中に拠点 T を少なくとも 1 回訪れたうえで、最終的に拠点 1 に戻ります。途中で他の拠点を経由しても構いませんし、同じ道路や同じ拠点を複数回通ることも許されます。同じ道路を複数回通った場合、通るたびにその道路の所要時間が加算されます。
このとき、拠点 1 を出発してから拠点 1 に戻るまでに通った道路の所要時間の合計として考えられる最小値を求めてください。
ただし、条件を満たす経路(拠点 1 を出発し、拠点 T を少なくとも 1 回訪れて拠点 1 に戻る経路)が存在しない場合は -1 を出力してください。
制約
- 2 \leq N \leq 10^5
- 1 \leq M \leq 2 \times 10^5
- 2 \leq T \leq N
- 1 \leq A_i < B_i \leq N(特に自己ループは存在しない)
- 1 \leq C_i \leq 10^9
- 同じ拠点の組を結ぶ道路は高々 1 本である
- 入力は全て整数である
入力
N M T A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
- 1 行目には、拠点の数 N 、道路の数 M 、必ず訪れるべき拠点の番号 T が、スペース区切りで与えられる。
- 続く M 行のうち i 行目には、i 番目の道路が結ぶ 2 つの拠点の番号 A_i , B_i と、その道路を通るのにかかる時間 C_i が、スペース区切りで与えられる。
出力
高橋君が拠点 1 を出発し、拠点 T を少なくとも 1 回訪れてから拠点 1 に戻るまでにかかる最小の合計時間を 1 行で出力せよ。条件を満たす経路が存在しない場合は -1 を出力せよ。
入力例 1
4 4 3 1 2 5 2 3 3 3 4 2 1 4 10
出力例 1
16
入力例 2
5 3 5 1 2 100 3 4 50 4 5 30
出力例 2
-1
入力例 3
6 8 4 1 2 10 1 3 15 2 3 5 2 4 20 3 4 8 3 5 12 4 6 6 5 6 3
出力例 3
46
Score : 400 pts
Problem Statement
Takahashi works part-time at a delivery company. There are N delivery hubs in this area, numbered from 1 to N.
There are M roads in this area, and the i-th road connects hub A_i and hub B_i bidirectionally. Traveling along this road takes C_i minutes in either direction.
Today, Takahashi must depart from hub 1, where the headquarters is located, deliver a package to a customer at hub T, and then return to hub 1.
Specifically, Takahashi starts at hub 1, travels along roads in sequence, visits hub T at least once during the journey, and ultimately returns to hub 1. He may pass through other hubs along the way, and he is allowed to traverse the same road or visit the same hub multiple times. If the same road is traversed multiple times, the travel time for that road is added each time it is traversed.
Find the minimum possible total travel time of the roads traversed from the time Takahashi departs hub 1 until he returns to hub 1.
If no valid route exists (a route that departs from hub 1, visits hub T at least once, and returns to hub 1), output -1.
Constraints
- 2 \leq N \leq 10^5
- 1 \leq M \leq 2 \times 10^5
- 2 \leq T \leq N
- 1 \leq A_i < B_i \leq N (in particular, there are no self-loops)
- 1 \leq C_i \leq 10^9
- There is at most one road connecting any pair of hubs
- All input values are integers
Input
N M T A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
- The first line contains the number of hubs N, the number of roads M, and the hub number T that must be visited, separated by spaces.
- The i-th of the following M lines contains the numbers of the two hubs A_i, B_i connected by the i-th road, and the time C_i required to travel along that road, separated by spaces.
Output
Output in one line the minimum total time for Takahashi to depart from hub 1, visit hub T at least once, and return to hub 1. If no valid route exists, output -1.
Sample Input 1
4 4 3 1 2 5 2 3 3 3 4 2 1 4 10
Sample Output 1
16
Sample Input 2
5 3 5 1 2 100 3 4 50 4 5 30
Sample Output 2
-1
Sample Input 3
6 8 4 1 2 10 1 3 15 2 3 5 2 4 20 3 4 8 3 5 12 4 6 6 5 6 3
Sample Output 3
46
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
高橋君は、横一列に並んだ N 個の花壇を管理しています。各花壇には 1 から N までの番号が付けられており、花壇 i には最初 C_i リットルの水が蓄えられています。
高橋君はこれから Q 回の操作を順番に行います。各操作は、前の操作の結果が反映された状態で行われます。操作は以下の 2 種類です。
- 操作 1(水やり):
1 l r v— 番号が l 以上 r 以下のすべての花壇それぞれに v リットルの水を追加する。 - 操作 2(確認):
2 l r— 番号が l 以上 r 以下のすべての花壇に蓄えられている水の量の合計値を出力する。
すべての操作 2 に対する答えを、与えられた順に求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq Q \leq 10^5
- 0 \leq C_i \leq 10^4 (1 \leq i \leq N)
- 操作 1 において、1 \leq l \leq r \leq N かつ 1 \leq v \leq 10^4
- 操作 2 において、1 \leq l \leq r \leq N
- 操作 2 は 1 回以上与えられる
- 入力はすべて整数である
- 操作 2 に対する答えは 0 以上 2^{63} - 1(符号付き 64 ビット整数の最大値)以下であることが保証される
入力
N Q
C_1 C_2 \ldots C_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
各 \text{query}_j (1 \leq j \leq Q) は、以下のいずれかの形式で与えられる。
1 l r v
2 l r
- 1 行目には、花壇の数を表す整数 N と操作回数を表す整数 Q が、スペース区切りで与えられる。
- 2 行目には、各花壇の初期の水の量を表す整数 C_1, C_2, \ldots, C_N が、スペース区切りで与えられる。
- 続く Q 行のそれぞれに、各操作が 1 つずつ与えられる。
- 操作 1 の場合は
1 l r vの形式で、操作の種類、区間の左端 l、区間の右端 r、追加する水の量 v の 4 つの整数がスペース区切りで与えられる。 - 操作 2 の場合は
2 l rの形式で、操作の種類、区間の左端 l、区間の右端 r の 3 つの整数がスペース区切りで与えられる。
出力
操作 2 が与えられるたびに、その時点での番号が l 以上 r 以下の花壇に蓄えられている水の量の合計値を 1 行に出力せよ。出力は操作が与えられた順に行うこと。
入力例 1
5 4 3 1 4 1 5 2 1 5 1 2 4 3 2 2 4 2 1 5
出力例 1
14 15 23
入力例 2
8 7 2 5 3 7 1 4 6 2 2 1 8 1 3 6 2 2 3 6 1 1 4 5 2 2 7 1 5 8 1 2 1 8
出力例 2
30 23 49 62
入力例 3
10 10 10 20 30 40 50 60 70 80 90 100 2 1 10 1 1 5 10 2 1 5 2 6 10 1 3 8 20 2 1 10 1 1 10 5 2 1 10 2 5 5 2 1 1
出力例 3
550 200 400 720 770 85 25
Score : 466 pts
Problem Statement
Takahashi manages N flower beds arranged in a horizontal row. Each flower bed is numbered from 1 to N, and flower bed i initially stores C_i liters of water.
Takahashi will perform Q operations in order. Each operation is performed on the state resulting from all previous operations. There are 2 types of operations:
- Operation 1 (Watering):
1 l r v— Add v liters of water to each flower bed with a number from l to r, inclusive. - Operation 2 (Query):
2 l r— Output the total amount of water stored across all flower beds with numbers from l to r, inclusive.
Find the answers to all operation 2 queries in the order they are given.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq Q \leq 10^5
- 0 \leq C_i \leq 10^4 (1 \leq i \leq N)
- For operation 1, 1 \leq l \leq r \leq N and 1 \leq v \leq 10^4
- For operation 2, 1 \leq l \leq r \leq N
- At least one operation 2 is given
- All input values are integers
- It is guaranteed that the answer to each operation 2 is between 0 and 2^{63} - 1 (the maximum value of a signed 64-bit integer), inclusive
Input
N Q
C_1 C_2 \ldots C_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Each \text{query}_j (1 \leq j \leq Q) is given in one of the following formats:
1 l r v
2 l r
- The first line contains an integer N representing the number of flower beds and an integer Q representing the number of operations, separated by a space.
- The second line contains integers C_1, C_2, \ldots, C_N representing the initial amount of water in each flower bed, separated by spaces.
- Each of the following Q lines contains one operation.
- For operation 1, it is given in the format
1 l r v, consisting of 4 integers separated by spaces: the operation type, the left endpoint l of the range, the right endpoint r of the range, and the amount of water v to add. - For operation 2, it is given in the format
2 l r, consisting of 3 integers separated by spaces: the operation type, the left endpoint l of the range, and the right endpoint r of the range.
Output
Each time an operation 2 is given, output the total amount of water stored in the flower beds with numbers from l to r, inclusive, at that point in time, on a single line. Output the results in the order the operations are given.
Sample Input 1
5 4 3 1 4 1 5 2 1 5 1 2 4 3 2 2 4 2 1 5
Sample Output 1
14 15 23
Sample Input 2
8 7 2 5 3 7 1 4 6 2 2 1 8 1 3 6 2 2 3 6 1 1 4 5 2 2 7 1 5 8 1 2 1 8
Sample Output 2
30 23 49 62
Sample Input 3
10 10 10 20 30 40 50 60 70 80 90 100 2 1 10 1 1 5 10 2 1 5 2 6 10 1 3 8 20 2 1 10 1 1 10 5 2 1 10 2 5 5 2 1 1
Sample Output 3
550 200 400 720 770 85 25