#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
int a[500000];
pair<int, int> sums[500000];
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
FOR(i, 0, n) cin >> a[i];
int 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);
int 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) {
int end = (sums[i].second + window) % n;
if (end >= curr_start) {
cout << sums[i].first << '\n';
break;
}
rotation = end - curr_start + n + 1;
} else {
int end = (curr_start + rotation) % n;
if (end >= sums[i].second) {
cout << sums[i].first << '\n';
break;
}
rotation = end - sums[i].second + n + 1;
curr_start = sums[i].second;
}
}
}
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 |
504 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 |
504 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 |
504 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 |
504 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 |
- |