题库练习 Bear and Blocks
← 上一题 下一题 →

A10040 | Bear and Blocks

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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.

输入格式

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.

输出格式

Print the number of operations needed to destroy all towers.

输入输出样例

输入 #1
6
2 1 4 6 2 2
输出 #1
3
输入 #2
7
3 3 3 1 3 3 3
输出 #2
2
C++ 编辑器
输入
输出