This page is still under construction.

Parts of this page are still being built. What you see may change.

Fireworks

Time limit1sMemory limit256 MB

Summary
Remove N-2 interior piles one by one; each removal drops the nearest surviving neighbors by 1. Minimize the larger of the two final piles.
Level

Medium7 of 10

Topics
Binary search, Greedy, Array, Implementation
Solved
No attempts yet

Problem

The people of the kingdom of Polymath set off fireworks with fire stones. Today's fireworks show will use NN firework piles.

You repeat the following operation exactly N−2N-2 times to set off the fireworks.

  • Choose one firework pile other than the two at the ends.
  • Set off every firework in that pile.
  • The exploded pile disappears, and the heights of the nearest remaining piles on its left and right each decrease by 1.

After the fireworks show ends, only two firework piles remain. A pile used in one show cannot be reused, so you want to minimize the larger of the heights of the two remaining piles. Write a program that finds this value.

Input

The first line gives the number of firework piles NN. The next line gives the heights of the piles A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N.

Output

Print the minimum possible value of the larger of the two firework piles left at the end.

Constraints

  • 3≤N≤2×1053 \le N \le 2 \times 10^5
  • N≤Ai≤109N \le A_i \le 10^9

Examples2

  1. Example 1

    Input
    5
    7 6 8 6 9
    
    Expected output
    6
    
  2. Example 2

    Input
    3
    7 7 3
    
    Expected output
    6