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.

题意: 就是给你N个高度,每次删除和外界相接触的方块,问多少次可以删完

竟然是Dp

对于每一个高度, 其决定值得是两边的高度,然而直接暴力T了,应该Dp

Dp【i】表示 第i个高度在第几秒会被完全删完

从左往右考虑一次, 从右往左考虑一次

然后对于每个 Dp值取min, 所有值取MAX;

(感谢学长ChildOfHulu♂指导)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int Num[maxn];
int Dp[maxn];
int Dp2[maxn];
set<int> S;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin >> n;
for(int i = ; i <= n; ++i)
{
//int t;
cin >> Num[i];
}
for(int i = ; i <= n; ++i)
Dp[i] = min(Dp[i-]+,Num[i]);
for(int i = n; i >= ; i--)
Dp2[i] = min(Dp2[i+]+,Num[i]);
int ans = ;
for(int i = ; i <= n; ++i)
ans = max(ans, min(Dp[i],Dp2[i]));
cout << ans << endl;
}

最新文章

  1. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
  2. Spring学习记录(二)---容器和bean属性配置
  3. Java: IO 学习小结
  4. NetApp常用检查命令
  5. 开启Python之路
  6. php实现数字格式化,数字每三位加逗号的功能函数
  7. 《ASP.NET1200例》&lt;asp:DataList&gt;分页显示图片
  8. 使用IE浏览器下载时候窗口一闪而过
  9. httpclient发送multipart/form-data类型参数和用MultipartRequest接收参数
  10. SOA面向服务化编程架构(dubbo)
  11. Volley完全解析
  12. .Net用js实现aspx页面删除TextBox输入框的前后空格
  13. java转换字符串编码格式 (解码错误,重新解码)
  14. Raspberry 3安装docker
  15. 我的MYSQL学习心得(六)
  16. 利用LinkedList实现洗牌功能
  17. 《java.util.concurrent 包源码阅读》15 线程池系列之ScheduledThreadPoolExecutor 第二部分
  18. LAMP第三部分php,mysql配置
  19. java 跳出多层循环
  20. hadoop常用操作命令

热门文章

  1. 函数的作用域、global与nonlocal
  2. JS 样式字符串 转 JSON对象
  3. 数据结构Java实现02----单向链表的插入和删除
  4. 开源框架.netCore DncZeus学习(三)增加一个菜单
  5. XML外部实体注入漏洞(XXE)
  6. C# &quot;XXX.XmlSerializers”的程序集未能加载到..
  7. 使用PHP连接数据库实现留言板功能
  8. day 5 - 1 字典(dict)
  9. 爬虫BS4—淘女郎
  10. mongodb系列~mongodb定时删除数据