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. Eigen中的noalias(): 解决矩阵运算的混淆问题

    作者:@houkai本文为作者原创,转载请注明出处:http://www.cnblogs.com/houkai/p/6349990.html 目录 混淆例子解决混淆问题混淆和component级的操作 ...

  2. 3-C++程序的结构1.3

    类的友元 一个类之外的函数,又与该类有特殊关系! 友元关系提供了不同类或对象的成员函数之间.类的成员函数与一般函数之间进行数据共享的机制.通俗地说,友元关系就是一个类主动声明那些其他类或函数是它的朋友 ...

  3. [CVE-2017-5487] WordPress <=4.7.1 REST API 内容注入漏洞分析与复现

    记录下自己的复现思路 漏洞影响: 未授权获取发布过文章的其他用户的用户名.id 触发前提:wordpress配置REST API 影响版本:<= 4.7 0x01漏洞复现 复现环境: 1) Ap ...

  4. CodeForces 524C The Art of Dealing with ATM (二分)

    题意:给定 n 种不同的钞票,然后用q个询问,问你用最多k张,最多两种不同的钞票能不能组成一个值. 析:首先如果要求的值小点,就可以用DP,但是太大了,所以我们考虑一共最多有n * k种钞票,如果每次 ...

  5. MyBatis中的RowBounds

    myBatis中实现分页的方式是采用RowBounds这个类,用法如下,xml语句不变 传入两个参数,strat起始行, limit是当前页显示多少条数据,原理是RowBounds在处理分页时,只是简 ...

  6. Unity5自动命名Assetbundle并打包

    http://www.shihuanjue.com/?p=57 using UnityEngine; using System.Collections; using UnityEditor; usin ...

  7. GitHub使用方法(初级)

    [初识Github] Git 是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目 ...

  8. E. XOR and Favorite Number (莫队板子题)

    题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { , ...

  9. cmd 查看端口占用情况

    netstat -nao|findstr 端口号 打开任务管理器查看

  10. 在项目中移除CocoaPods

    如果你觉得CocoaPods让你的项目出现了问题,不好用甚至是恶心,想将其从项目中彻底移除,也有方法: 1.删除工程文件夹下的Podfile.Podfile.lock和Pods文件夹. 2.删除xcw ...