http://codeforces.com/contest/574/problem/D

Bear and Blocks

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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

题目大意 每次只能消最外层的砖 问多少次能消完

看hint图吧 等价与从右方看 从左到右峰依次为  2 1 4 3 2 1 从左方看  从左到右峰依次为 1 1 2 3 2 2

比较每个位置需要消去的最少次数 依次为 1 1 2 3 2 2的峰

看到这里是不是就明白了呢

我们只需要把山峰等效为 突起 如 1 2 2 3 4 3这样的形式就ok了

具体操作见代码 tw菊苣的dp写法还不是很理解 再研究一下

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
inline void ri(int &num){
num=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')num=num*+ch-'',ch=getchar();
num*=f;
}
const int N=1e5+;
int l[N],r[N],a[N];
int main()
{
int n;
ri(n);
for(int i=;i<=n;i++)ri(a[i]);
for(int i=;i<=n;i++) l[i]=min(l[i-]+,a[i]);
for(int i=n;i>=;i--) r[i]=min(r[i+]+,a[i]);
int mx=-;
for(int i=;i<=n;i++) mx=max(mx,min(l[i],r[i]));
printf("%d\n",mx);
return ;
}

AC代码

校内选拔I题题解 构造题 Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) ——D的更多相关文章

  1. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)

    以后每做完一场CF,解题报告都写在一起吧   暴力||二分 A - Bear and Elections 题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢 ...

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

    B. Bear and Blocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pr ...

  3. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解

    A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...

  4. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列

                                                    A. Bear and Elections                               ...

  5. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers 枚举

                                          B. Bear and Three Musketeers                                   ...

  6. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker

                                                  C. Bear and Poker                                     ...

  7. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing

    题目链接:http://codeforces.com/contest/573/problem/C题目大意:在两行无限长的点列上面画n个点以及n-1条边使得构成一棵树,并且要求边都在同一平面上且除了节点 ...

  8. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  9. BZOJ 3097: Hash Killer I【构造题,思维题】

    3097: Hash Killer I Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 963  Solved: 36 ...

随机推荐

  1. python 进程和线程的区别

    1.开进程的开销远大于开线程 import time from threading import Thread from multiprocessing import Process def piao ...

  2. c++重载输入输出运算符

    1 最好打断点看看哦 2例子 #include <iostream> using namespace std; class Complex2 { public: Complex2(, ) ...

  3. 使用命令把类打成jar包

    测试用类 public class Hello { public static void main(String[] args) { System.out.println("hello wo ...

  4. phpstudy的mysql版本升级至5.7

    phpstudy安装的mysql版本一般都是5.5或5.4的,但是有时候做项目又必须用到mysql5.7版本,所以我们现在来看一下如何在phpstudy的环境下将mysql版本升级至5.7 温馨提醒: ...

  5. web前端篇:JavaScript基础篇(易懂小白上手快)-1

    目录 详细内容: 0.JavaScript的引入 1.第一个JavaScript 2.变量 3.变量的类型 4.数组 5.条件语句 6.三元运算符 7.循环 8.函数 9.对象(object): 10 ...

  6. 花花的森林(倍增,LCA

    花花的森林,嗯,这是一篇正经的题解. 模拟考的时候没有看出来要怎么求啊,暴力地树形DP.换根.合并.求直径.居然也险险地拿到了80分,不过我们要正经地想正解. 容易想到我们可以让时光倒流,让空间扭转, ...

  7. 笔记-JavaWeb学习之旅11

    请求转发:一种在服务器内部的资源跳转方式 使用步骤 1.通过request对象获取请求转发器对象:RequestDispatcher getRequestDispatcher(String path) ...

  8. PHP不重新编译,单独添加模块扩展的方法

    php自身提供了很多扩展,比如curl,gmp, mbstring等.我们在编译安装php时未必安装了所有扩展.那么在安装完php后,如果想单独安装某个php自身的扩展怎么办呢? 我们以curl扩展模 ...

  9. struts2与struts1的比较

    struts2相对于struts1来说简单了很多,并且功能强大了很多,我们可以从几个方面来看: 从体系结构来看:struts2大量使用拦截器来出来请求,从而允许与业务逻辑控制器 与 servlet-a ...

  10. 在开发中经常会有多级跳转 viewcontroller的问题,然后有时不一定要一级一级的返回,可能直接返回到某个根视图控制器或某个指定的控制器.

    其中采用navigationController pushViewController 的方法,比如我从主页面跳转到了4级页面,又从4级页面跳转到了2级页面,然后从2级页面跳转到了4级页面然后在重4级 ...