思路:找一下规律,然后就左右各扫一遍就好啦



#include<bits\stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int a[maxn];
int dp[maxn];
int l[maxn];
int r[maxn];

int main()
{
	int n;
	cin >> n;
	for(int i = 0;i<n;i++)
		cin >> a[i];
    l[0]=1;
	int ans = 0;
	r[n-1]=1;
	for(int i = 1;i<n;i++)
		l[i]=min(l[i-1]+1,a[i]);
	for(int i = n-2;i>=0;i--)
		r[i]=min(r[i+1]+1,a[i]);
	for(int i = 0;i<n;i++)
		dp[i]=min(l[i],r[i]);
	for(int i = 0;i<n;i++)
		ans = max(dp[i],ans);
	cout << ans << endl;
}




D. Bear and Blocks
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
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.


Output
Print the number of operations needed to destroy all towers.


Examples
input
6
2 1 4 6 2 2
output
3
input
7
3 3 3 1 3 3 3
output
2
Note
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.


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