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>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
ll a[500000];
pair<ll, ll> sums[500000];
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
FOR(i, 0, n) cin >> a[i];
ll window = (n + 1) / 2, sum = 0;
FOR(i, 0, window) sum += a[i];
FOR(i, 0, n) {
sums[i] = {sum, i};
sum += a[(i + window) % n] - a[i];
}
sort(sums, sums + n);
ll curr_start = sums[0].second, rotation = window;
FOR(i, 1, n) {
if (sums[i].second == (curr_start + rotation) % n) {
cout << sums[i].first << '\n';
break;
} else {
if ((curr_start + rotation) % n >= sums[i].second) {
ll end = (sums[i].second + window) % n;
if (end >= curr_start) {
cout << sums[i].first << '\n';
break;
}
rotation = end - curr_start + n + 1;
} else {
ll end = (curr_start + rotation) % n;
if (end >= sums[i].second) {
cout << sums[i].first << '\n';
break;
}
curr_start = sums[i].second;
rotation = end - curr_start + n + 1;
}
}
}
return 0;
}
Compilation message (stderr)
hac.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
#pragma GCC Optimize("O3")
# | 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... |