Codeforces Round 318 [RussianCodeCup Thanks-Round] (Div. 1)
B
Bear and Blocks
Codeforces
1600
原题
← AC →
翻译中…

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 $*h*_{*i*}$ 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

翻译中…

The first line contains single integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$).

翻译中…

The second line contains $*n*$ space-separated integers $*h*_{1}, *h*_{2}, ..., *h*_{*n*}$ ($1 ≤ *h*_{*i*} ≤ 10^{9})$ — sizes of towers.

翻译中…

Output

翻译中…

Print the number of operations needed to destroy all towers.

翻译中…

Note

翻译中…

The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.

翻译中…

image

翻译中…

After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

翻译中…

样例

Input #1
6
2 1 4 6 2 2
Output #1
3
InputCopy OutputCopy
Input #2
7
3 3 3 1 3 3 3
Output #2
2
InputCopy OutputCopy
题目信息
题号
573B
时间限制
1 s
内存限制
256 MB
标签
二分
数据结构
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。