#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> values(2 * n + 1);
values[0] = 0;
for (int i = 1; i <= n; i++){
cin >> values[i];
values[n + i] = values[i];
}
for (int i = 1; i <= 2 * n; i++) values[i] += values[i - 1];
int win_size = (n + 1) / 2;
multiset<int> totals;
vector<int> res(n + 1, INT_MAX);
for (int i = 1; i <= 2 * n; i++){
if (i + win_size - 1 < 2 * n) totals.insert(values[i + win_size - 1] - values[i - 1]);
if (i > win_size) totals.erase(totals.find(values[i - 1] - values[i - 1 - win_size]));
int real_pos = (i - 1) % n + 1;
res[real_pos] = min(res[real_pos], *totals.begin());
}
int ans = 0;
for (int i = 1; i <= n; i++) ans = max(ans, res[i]);
cout << ans;
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... |