Fireworks
Time limit1sMemory limit256 MB
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 firework piles.
You repeat the following operation exactly 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 . The next line gives the heights of the piles .
Output
Print the minimum possible value of the larger of the two firework piles left at the end.