#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
int len = (n + 1) / 2;
vector<int> a(n);
for (int& i : a) cin >> i;
partial_sum(a.begin(), a.end(), a.begin());
auto at = [&](int i) -> int {
i = (i % n + n) % n;
int e = (i + len - 1) % n;
if (i <= e) {
return a[e] - (i == 0 ? 0 : a[i - 1]);
}
return a[n - 1] - a[i - 1] + a[e];
};
multiset<int> ms;
for (int i = -len; i < 0; ++i) ms.insert(at(i));
int ans = -1;
for (int i = 0; i < n; ++i) {
ms.erase(ms.find(at(i - len)));
ms.insert(at(i));
ans = max(ans, *ms.begin());
}
cout << ans << '\n';
return 0;
}
# | 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... |