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. CSS3:nth-child()伪类选择器,Table表格奇偶数行定义样式

    转自爱设计 原文链接http://www.dangshopex.com/jishufenxiang/WEBkaifajishu/8653.html CSS3的强大,让人惊叹,人们在惊喜之余,又不得不为 ...

  2. ThinkPHP3.2.3中,查询语句中in的使用方法。

    //删除分类 public function del(){ $cid = I('get.cid'); $cate = M('category')->field('cid,pid')->se ...

  3. TP5之一次选择多张图片并预览

    点击选择图片(可选多张),确定后将选择的图片显示在页面上,已经选择的图片也可以删除,点击提交将图片提交给后台. 1.效果图 2.code 用input标签并选择type=file,记得带上multip ...

  4. HDU3038【种类并查集】

    题意: 给出m组区间[a,b],以及其区间的和,问有矛盾的有几组: 思路: 种类并查集. 主要是几个关系:同类元素的关系,父亲与儿子的关系,不同类元素的关系: 我们可以类似看作一个前缀和,sum[x] ...

  5. MonogoDb的角色分类

    引用:  http://blog.csdn.net/kk185800961/article/details/45619863 https://docs.mongodb.org/manual/refer ...

  6. mysql 5.6 安装x64版本

    从mysql下载的 32bit的 msi installer 后 , 安装的时候没有发现选择x64的地方, 最后安装完毕后发现server是32bit的,只能删除server(  installer ...

  7. github的上传本地文档

    自从使用github以来,一直都是在github网站在线上传文件到仓库中,但是有时因为网络或者电脑的原因上传失败.最重要的原因是我习惯本地编辑,完成以后再一起上传github.看过了几个教程,总结出最 ...

  8. Eclipse-Hadoop-Plugin编译

    1 JDK配置 1.1 安装JDK 具体可以百度,网上教程很多,有JAVA开发环境的都是已经安装的. 1.2 配置环境变量 设置JAVA_HOME.CLASSPATH.PATH等.具体可以百度,有JA ...

  9. dumpe2fs: Bad magic number in super-block

    今天使用tune2fs和dumpe2fs来查看文件系统信息,出现如下图所示错误提示: 解决方法: 1.原来tune2fs和dumpe2fs只能打开ext3/ext4等文件类型. dumpe2fs - ...

  10. UVa-11582:Colossal Fibonacci Numbers!(模算术)

    这是个开心的题目,因为既可以自己翻译,代码又好写ヾ(๑╹◡╹)ノ" The i’th Fibonacci number f(i) is recursively defined in the f ...