#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
hac.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
#pragma GCC Optimize("O3")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |