0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 03:58:48 +00:00
OI-codes/Luogu/T208078/T208078.cpp

22 lines
415 B
C++
Raw Normal View History

2021-10-30 11:09:31 +00:00
#include <bits/stdc++.h>
using namespace std;
long long n, a[100005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i > 2; i--) {
if (abs(a[i - 1] - a[i]) > abs(a[i - 1] + a[i])) {
a[i - 1] -= a[i];
} else {
a[i - 1] += a[i];
}
}
cout << max(a[1] - a[2], a[1] + a[2]) << endl;
return 0;
}