Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题

时间:2024-01-09 16:40:26

B. Bear and Blocks

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/573/problem/B

Description

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.

Sample Input

6
2 1 4 6 2 2

Sample Output

3

HINT

题意

每次会消除与外界相互接触的方块,问你得消除多少次,才能把所有方块都消除完

题解

对于每个数,我们统计一下从左边消除得消除多少次,从右边消除得消除多少次

然后O(n)跑一遍就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll ans=;
int main()
{
n=read();
for(int i=;i<=n;i++)
a[i]=read();
for(int i=;i<=n;i++)
b[i]=min(b[i-]+,a[i]);
for(int i=n;i>=;i--)
c[i]=min(c[i+]+,a[i]);
for(int i=;i<=n;i++)
ans=max(ans,min(b[i],c[i]));
cout<<ans<<endl;
}