题目地址


基本思路:

  • 连续增减性.

#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=2e5;
int h[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&h[i]);
	}
	int ans=0,tmp=0;
	for(int i=1;i<=n;i++){
		if(h[i]>tmp)ans+=h[i]-tmp;
		tmp=h[i];
	}
	printf("%d\n",ans);
	return 0;
}