Title Description
Chris Kindergarten held annual "building blocks competition." This year the content of the game is to build a width of n building, the building can be seen as an n-block width of 1 building blocks in a final height of the building blocks of the i need is hi.
Before beginning to build, no blocks (n blocks can be viewed as building blocks to a height of 0). Each subsequent operation, the children may be selected for a continuous interval [l, r], then the second L between the first block to R block (including a block of L and R blocks) increases the height of all the building blocks 1, respectively.
M is a smart little kids, she soon came up with the best strategy for the construction of the building, so that the required minimum number of construction operations. But she was not a diligent hands of children, therefore I would like you to help implement this strategy, and to obtain a minimum number of operations.
Input and output format
input format:
Input file block.in
Comprising two input lines, the first line contains an integer n, denotes the width of the building.
The second line contains n integers, the integer i is hi.
Output formats:
The output file is block.out
Only one line, namely the construction of the required minimum number of operations.
Sample input and output
Input Sample # 1:
. 5
2 1 2. 4. 3
Output Sample # 1:
5
Explanation
Sample [explain]
One of the best possible, select
[1,5] [1,3] [2,3] [3,3] [5,5]
【data range】
For 30% of the data, it is 1 ≤ n ≤ 10;
For 70% of the data, it is 1 ≤ n ≤ 1000;
To 100% of the data, it is 1 ≤ n ≤ 100000,0 ≤ hi≤ 10000.
This question and before we can find no decline in the result is a sequence after sequence of this one minus one
see the code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int h;
int hi[100010];
int ans=0;
int la=0;
scanf("%d",&h);
for(int i=0;i<h;i++){
scanf("%d",&hi[i]);
}
for(int i=0;i<h;i++){
if(hi[i]>hi[i-1]){
ans+=hi[i]-hi[i-1];
}
}
printf("%d",ans);
return 0;
}