This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(2 * n);
int S = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i + n] = a[i];
S += a[i];
}
vector<int> pref(2 * n + 1, 0);
for(int i = 0; i < 2 * n; i++) {
pref[i + 1] = pref[i] + a[i];
}
int ans = INT_MAX - 5;
//cerr << "moves:" << (n + 1) / 2 << '\n';
for(int i = 0; i < n; i++) {
int sum = pref[i + (n + 1) / 2] - pref[i];
//cerr << sum << ' ' << S - sum << '\n';
ans = min(ans, abs(sum - (S - sum)));
}
cout << (ans + S) / 2 << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |