-->
当前位置:首页 > 题库

PROGRAMMING:Building block competition

Luz5年前 (2021-05-10)题库388
Chunchun kindergarten held the annual "building block competition".
The content of this year's competition is to build a building with a width of N. the building can be regarded as composed of N blocks with a width of 1. The final height of the I block needs to be hi.
Before the start of building, there are no building blocks (which can be regarded as blocks with a height of ﹥ 0).
Next, for each operation, the children can select a continuous interval [l, R], and then increase the height of all building blocks from block l to block R (including block L and block R) by 1.
Xiaom is a smart child, she quickly came up with the best strategy to build the building, so that the number of operations required to build the least.
But she is not a diligent child, so I would like to ask you to help achieve this strategy, and find the minimum number of operations.
###Input format:
The input contains two lines. The first line contains an integer n, which represents the width of the building.  
The second line contains n integers, and the i-th integer is hi( 1≤n≤1e5,0≤hi≤10000)
###Output format:
Only one row is the minimum number of operations required to build.
###Input example:
```in
five
2 3 4 1 2
```
###Output example:
```out
five
```







answer:If there is no answer, please comment