Files
python/TangDou/LuoGuBook/P5019.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

18 lines
331 B
C++

#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;
}