2708.Bear and Blocks

Time Limit: 1s Memory Limit: 256MB

Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.

Limak will repeat the following operation till everything is destroyed.

Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.

Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

Input Format(From the terminal/stdin)

The first line contains single integer n (1 \le n \le 105).

The second line contains n space-separated integers h1,h2,...,hn (1 \le hi \le 109) - sizes of towers.

Output Format(To the terminal/stdout)

Print the number of operations needed to destroy all towers.

Sample Input 1

Copy
6
2 1 4 6 2 2
 \n
 · · · · · \n

Sample Output 1

Copy
3
 \n

Sample Input 2

Copy
7
3 3 3 1 3 3 3
 \n
 · · · · · · \n

Sample Output 2

Copy
2
 \n

Hints

The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
2708_1.png After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

Submit

请先 登录

© 2025 FAQs