# 积木大赛(Building block competition)-其他

## 积木大赛(Building block competition)

5

2 3 4 1 2

5

“`

``//// Created by 23011 on 15/1/2022.//#include<iostream>using namespace std;const int maxn=100000+10;int a[maxn];int main(){    int n;    scanf("%d",&n);    for (int i=0;i<n;i++) scanf("%d",&a[i]);    int now=a[0],ans=a[0];    for(int i=1;i<n;i++){        if (a[i]>now) ans+=(a[i]-now);        now=a[i];    }    printf("%d",ans);    return 0;}``
————————

< strong > Title Description < / strong >

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 ＾ and the final height of the ＾ I block needs to be ＾ hi.

Before the start of construction, there are no building blocks (which can be regarded as # n # blocks with a height of # 0). Next, for each operation, children can select a continuous interval [l, R], and then increase the height of all building blocks from ＾ L ＾ block to ＾ R ＾ block (including ＾ L ＾ block and ＾ R ＾ block) by ＾ 1 respectively.

Little m is a smart child. She quickly came up with the best strategy for building a building to minimize the number of operations required. But she is not a diligent child, so she wants to ask you to help implement this strategy and find the minimum number of operations.

< strong > input format < / strong >

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 ， integer is hi.

< strong > output format < / strong >

Only one row, the minimum number of operands required for construction.

< strong > input data1 < / strong >

five

2 3 4 1 2

< strong > output data1 < / strong >

five

One of the feasible best schemes is to select [1,5], [1,3], [2,3], [3,3], [5,5] successively.

Data range and tips

For 30% of the data, there is ﹤ 1 ≤ n ≤ 10;

For 60% of the data, there are 0.01 ≤ n ≤ 1000;

For 100% data, there are 1 ≤ n ≤ 100000, 0 ≤ hi ≤ 10000.

“`

``//// Created by 23011 on 15/1/2022.//#include<iostream>using namespace std;const int maxn=100000+10;int a[maxn];int main(){    int n;    scanf("%d",&n);    for (int i=0;i<n;i++) scanf("%d",&a[i]);    int now=a[0],ans=a[0];    for(int i=1;i<n;i++){        if (a[i]>now) ans+=(a[i]-now);        now=a[i];    }    printf("%d",ans);    return 0;}``