menu ZJOJ
account_circle 请登录
home
首页
book
题目
apps
分类
play_circle_outline
状态
assessment
竞赛
assignment
作业
equalizer
排名
assignment_ind
登录
person_add
注册
1554: 铺设道路
时间限制:1.000s
内存限制:125MB

题目描述

小紫是一名道路工程师,负责铺设一条长度为 lns="http://www.w3.org/1998/Math/MathML">n 的道路。

铺设道路的主要工作是填平下陷的地表。整段道路可以看作是 lns="http://www.w3.org/1998/Math/MathML">n 块首尾相连的区域,一开始,第 lns="http://www.w3.org/1998/Math/MathML">i 块区域下陷的深度为 lns="http://www.w3.org/1998/Math/MathML">d_i 。

小紫每天可以选择一段连续区间 lns="http://www.w3.org/1998/Math/MathML">[L,R] ,填充这段区间中的每块区域,让其下陷深度减少 lns="http://www.w3.org/1998/Math/MathML">1。在选择区间时,需要保证,区间内的每块区域在填充前下陷深度均不为 lns="http://www.w3.org/1998/Math/MathML">0 。

小紫希望你能帮他设计一种方案,可以在最短的时间内将整段道路的下陷深度都变为 lns="http://www.w3.org/1998/Math/MathML">0 

输入格式

输入包含两行,第一行包含一个整数 lns="http://www.w3.org/1998/Math/MathML">n,表示道路的长度。 第二行包含 lns="http://www.w3.org/1998/Math/MathML">n 个整数,相邻两数间用一个空格隔开,第 lns="http://www.w3.org/1998/Math/MathML">i 个整数为 lns="http://www.w3.org/1998/Math/MathML">d_i 。

输出格式

输出仅包含一个整数,即最少需要多少天才能完成任务。

样例输入 content_copy

6   
4 3 2 5 3 5 

样例输出 content_copy

9

提示/说明

【样例解释】

一种可行的最佳方案是,依次选择: lns="http://www.w3.org/1998/Math/MathML">[1,6]lns="http://www.w3.org/1998/Math/MathML">[1,6]lns="http://www.w3.org/1998/Math/MathML">[1,2]lns="http://www.w3.org/1998/Math/MathML">[1,1]lns="http://www.w3.org/1998/Math/MathML">[4,6]lns="http://www.w3.org/1998/Math/MathML">[4,4]lns="http://www.w3.org/1998/Math/MathML">[4,4]lns="http://www.w3.org/1998/Math/MathML">[6,6]lns="http://www.w3.org/1998/Math/MathML">[6,6]

【数据规模与约定】

对于 lns="http://www.w3.org/1998/Math/MathML">30\% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 ≤ n ≤ 10 ;
对于 lns="http://www.w3.org/1998/Math/MathML">70\% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 ≤ n ≤ 1000 ;
对于 lns="http://www.w3.org/1998/Math/MathML">100\% 的数据,lns="http://www.w3.org/1998/Math/MathML">1 ≤ n ≤ 100000 , 0 ≤ d_i ≤ 10000 。