/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 333 点
問題文
高橋君は山の斜面に並んだ N 個の貯水タンクを管理しています。これらのタンクは山の上から下に向かって一列に並んでおり、i 番目のタンクには現在 A_i リットルの水が入っています。
各タンクには特殊なバルブが付いており、このバルブを開けると水を下流のタンクに流すことができます。具体的には、i 番目のタンク( 1 \leq i \leq N - 1 )のバルブを開けると、その時点でそのタンクに入っている水の半分(リットル単位の小数点以下切り捨て)が i + 1 番目のタンクに移動します。
高橋君はこの操作を好きな回数( 0 回でも可)、好きな順序で行うことができます。同じタンクのバルブを何度開けても構いません。
最終的に、高橋君は最も下流にある N 番目のタンクの水だけを農業用水として使用します。
高橋君が使用できる水の最大量を求めてください。
制約
- 1 \leq N \leq 10^6
- 0 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N A_1 A_2 \cdots A_N
- 1 行目には、タンクの数を表す N が与えられる。
- 2 行目には、各タンクに入っている水の量を表す A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
高橋君が N 番目のタンクから使用できる水の最大量をリットル単位で 1 行で出力せよ。
入力例 1
3 10 0 0
出力例 1
8
入力例 2
4 1 2 3 4
出力例 2
7
入力例 3
10 7 0 15 3 8 21 0 5 13 2
出力例 3
65
入力例 4
25 100 0 250 17 999 1 64 128 256 512 1024 3 7 11 19 23 42 58 73 91 0 314 159 265 358
出力例 4
4750
入力例 5
1 0
出力例 5
0
Score : 333 pts
Problem Statement
Takahashi manages N water tanks lined up on a mountain slope. These tanks are arranged in a line from the top to the bottom of the mountain, and the i-th tank currently contains A_i liters of water.
Each tank has a special valve that allows water to flow into the downstream tank when opened. Specifically, when the valve of the i-th tank ( 1 \leq i \leq N - 1 ) is opened, half of the water in that tank at that moment (rounded down to the nearest integer in liters) is transferred to the i + 1-th tank.
Takahashi can perform this operation any number of times (possibly 0 times), in any order. The valve of the same tank may be opened multiple times.
In the end, Takahashi will use only the water in the N-th tank, which is the most downstream, for agricultural purposes.
Find the maximum amount of water that Takahashi can use.
Constraints
- 1 \leq N \leq 10^6
- 0 \leq A_i \leq 10^9
- All input values are integers.
Input
N A_1 A_2 \cdots A_N
- The 1-st line contains N, representing the number of tanks.
- The 2-nd line contains A_1, A_2, \ldots, A_N, representing the amount of water in each tank, separated by spaces.
Output
Print the maximum amount of water, in liters, that Takahashi can use from the N-th tank in a single line.
Sample Input 1
3 10 0 0
Sample Output 1
8
Sample Input 2
4 1 2 3 4
Sample Output 2
7
Sample Input 3
10 7 0 15 3 8 21 0 5 13 2
Sample Output 3
65
Sample Input 4
25 100 0 250 17 999 1 64 128 256 512 1024 3 7 11 19 23 42 58 73 91 0 314 159 265 358
Sample Output 4
4750
Sample Input 5
1 0
Sample Output 5
0