Title Description Description
Spring and Spring Kindergarten held the annual "Building Block Contest". This year's game is to build a building with a width of n, the building can be seen by the n block width of 1 blocks, the final height of block I need to be hi.
Before the construction begins, there is no building block (it can be seen as a block of n blocks of height 0). After each operation, the children can select a continuous interval [l,r] and then increase the height of all blocks from block L to block R (including Block L and R Block) by 1 respectively.
Little M was a clever little friend, and she soon came up with the best strategy for building, making the minimum number of operations required. But she is not a diligent child, so I would like to ask you to help achieve this strategy, and to find the minimum number of operations.
Enter a description input Description
The input contains two lines, and the first row contains an integer n, which indicates the width of the building.
The second line contains n integers, and the first integer is hi.
outputs description output Description
Only one row, which is the minimum number of operations required to build.
sample input to sample
5
2 3 4) 1 2
Sample output Sample outputs
5
data size & Hint
One of the best possible scenarios, select [1,5] [1,3] [2,3] [3,3] [5,5]
For 30% of the data, there are 1≤n≤10;
For 70% of the data, there are 1≤n≤1000;
For 100% of the data, there is 1≤n≤100000,0≤hi≤10000.
Conclusion Question:
#include <iostream>#include<stdio.h>using namespacestd;intn,a[100002],i,j,k,sum,high;intMain () {CIN>>N; for(i=1; i<=n;i++) Cin>>A[i]; for(i=1; i<=n;++i) { high=a[i-1]; if(a[i]>High ) Sum+=a[i]-High ; } cout<<sum; return 0;}
Codevs 3288 Bricks Competition