You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
331 B

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000010;
int a[N];
LL ans;
int n;
//贪心法
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) if (a[i] > a[i - 1]) ans += a[i] - a[i - 1];
cout << ans;
return 0;
}