Array modification

3.5

41 votes
Algorithms, Dynamic Programming, Greedy Algorithms
Problem

M as a prisoner loves playing with his array a1,a2,...,an, he can do following operation as much as he wants:

  • Choose two integers i,j that 1i,jn and |ij|=1 and also ai2.
  • Then add 1 to aj (aj=aj+1) and subtract 2 from ai (ai=ai2).

M thinks beautifulness of an array is maximum value of it (max(a1,a2,...,an)).

What is the maximum value of beautifulness that M can get after doing above operation as much as he wants?

Input

First line contains only n, length of array.

Second line contains the array elements a1,a2,...,anseparated by space.

2n2×105

1ai109

Output

The only line of output contains an integer, maximum beautifulness value that M can get.

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

M can do the operation on i=1,j=2 then on i=2,j=3 then on i=5,j=4 and then on i=4,j=3.

After operations array becomes 1,1,6,1,1.

Editor Image

?