From 56273f8b48d00ec34dd859fd01851c6782e261e7 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sat, 30 Oct 2021 19:09:31 +0800 Subject: [PATCH] T208078 [Kubic] Addition R61305013 --- Luogu/contest/54519/T208078/T208078.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Luogu/contest/54519/T208078/T208078.cpp diff --git a/Luogu/contest/54519/T208078/T208078.cpp b/Luogu/contest/54519/T208078/T208078.cpp new file mode 100644 index 00000000..9f051b03 --- /dev/null +++ b/Luogu/contest/54519/T208078/T208078.cpp @@ -0,0 +1,21 @@ +#include + +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; +}