Description
Eating chocolate is a hobby of TT students...
This is TT's birthday. tt woke up early in the morning and found a row of chocolate on the table, so I suddenly fell asleep! When TT was about to throw on the poor chocolate, he only coughed and said:AlgorithmHow is the review? I will test you ~ ......
Several pieces of chocolate are divided into N heaps and arranged in a straight line. At the beginning, TT stood before the first pile of chocolate (the number axis coordinate is 1). Three operations can be performed by TT:
1. Move one cell to the left
2. Shift one cell to the right
3. Take half of a pile of chocolate in front (round down, eg: 3/2 = 1)
It takes tt one second for each operation. Now, BB gives tt t seconds to get chocolate, but there is a requirement: TT must be from the first heap in T seconds (coordinate 1) start to the last heap (coordinate N), and stop at the end of t second at the last heap. Then BB will send all the chocolate obtained during this period to TT.
TT naturally won't let go of this great opportunity, so I carefully designed a method... can you figure out how many pieces of chocolate TT can get at most?
-
Input
-
Multiple groups of data, for each group of data:
The first line contains two integers, N and T, indicating the number and time of the chocolate heap (0 <n, T <100)
N positive integers in the second row, indicating the number of bars in each heap of chocolate a [I] (a [I] <1000000)
Data guarantee t time is enough from the start point to the end point
-
Output
-
Output a row of data in each group, that is, the answer to the question.
sample input
3 6
1 10 1
5 7
5 7 3 2 6
sample output
9
8
This is a simple simulation question, greedy. The idea is to use the total time minus the time for moving the lattice. The rest of the time is the time for obtaining chocolate. Then the most frequently searched chocolate is obtained, and the largest one is obtained after each fetch.
# include
int main () {int N, time; int I; Int J; int A [102]; int Max; double sum; int temp; while (scanf ("% d", & N, & time )! = EOF) {sum = 0; for (I = 0; I
MAX) {max = A [J]; temp = J ;}} sum + = max/2; A [temp] = A [temp]-Max/2;} printf ("%. 0lf \ n ", sum);} return 0 ;}