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.
The first line contains single integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.
Print the number of operations needed to destroy all towers.
6 2 1 4 6 2 2
3
7 3 3 3 1 3 3 3
2
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.

分析:
全都能被包围,那就是典型的递增序列,双向的(求1 2 3 4 。。。4 3 2 1)的最大高度。看到这个也就很好理解了,只是,看到题目的时候想不出。。。
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
#define read freopen("q.in","r",stdin)
#define LL long long
typedef pair<int,int> pii;
typedef pair<pii,int> P;
const int maxn =100005;
const int inf = 0x3ffffff;
int L[maxn],R[maxn];
int h[maxn];
int main()
{
int n,i,j;
while(~scanf("%d",&n))
{
h[0]=h[n+1]=0;
for(i=1;i<=n;i++)scanf("%d",&h[i]);
for(i=1;i<=n;i++)L[i]=min(L[i-1]+1,h[i]);
for(i=n;i>=1;i--)R[i]=min(R[i+1]+1,h[i]);
int res=0;
for(i=1;i<=n;i++)
{
res=max(res,min(L[i],R[i]));
}
cout<<res<<endl;
}
}