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

12 lines
273 B
C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n, x, pre = 0, ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++, pre = x)
scanf("%d", &x), ans += max(0, x - pre);
printf("%d", ans);
return 0;
}