代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 100000+10
int n,first,next,ans;
int main() {
scanf("%d",&n);
scanf("%d",&first);
ans = first;
for(int i = 2; i<=n;i++) {
scanf("%d",&next);
if(first<=next) {
ans+=next-first;
first = next;
}else if(first > next) {
first = next;
}
}
printf("%d",ans);
return 0;
}