0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:52:02 +00:00

T208078 [Kubic] Addition

R61305013
This commit is contained in:
Baoshuo Ren 2021-10-30 19:09:31 +08:00 committed by Baoshuo Ren
parent 7536cc5945
commit 56273f8b48
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,21 @@
#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;
}