2491: 【普及-】【P5019】铺设道路

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:2 解决:1

题目描述

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

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

春春每天可以选择一段连续区间 lns="http://www.w3.org/1998/Math/MathML">[,] ,填充这段区间中的每块区域,让其下陷深度减少 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">,表示道路的长度。 第二行包含 lns="http://www.w3.org/1998/Math/MathML"> 个整数,相邻两数间用一个空格隔开,第 lns="http://www.w3.org/1998/Math/MathML"> 个整数为 lns="http://www.w3.org/1998/Math/MathML"> 。

输出

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

样例输入 复制

6   
4 3 2 5 3 5 

样例输出 复制

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">110 ;
对于 lns="http://www.w3.org/1998/Math/MathML">70% 的数据,lns="http://www.w3.org/1998/Math/MathML">11000 ;
对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">1100000,010000 。

#include<bits/stdc++.h>
using namespace std;
int n, a[100005], f[100005];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    f[1] = a[1];
    for(int i = 2; i <= n; i++){
    	if(a[i] <= a[i-1]) f[i] = f[i-1];
    	else f[i] = f[i-1] + (a[i]-a[i-1]);
	}
	cout <<f[n];
	return 0;
}