AcWing 100. IncDec序列(差分)
程序员文章站
2022-07-12 17:50:58
...
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN], n, p, q;
signed main() {
//freopen("in", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 2;i <= n; i++){
if (a[i] - a[i - 1] > 0)
p += a[i] - a[i - 1];
else
q -= a[i] - a[i - 1];
}
cout << max(p, q) << endl << abs(p - q) + 1 << endl;
return 0;
}