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"
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(2 * n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i + n] = a[i];
}
vector<int> pref(a.size() + 1);
for (int i = 1; i < (int) pref.size(); i++) {
pref[i] = pref[i - 1] + a[i - 1];
}
int ans = 0, sz = n / 2, uk = 0;
multiset<int> st;
for (int i = 0; i < n; i++) {
while (uk + sz - 1 < i + n) {
st.insert({pref[uk + sz] - pref[uk]});
uk++;
}
st.erase(st.find(pref[i + sz] - pref[i]));
ans = max(ans, pref[n] - *st.rbegin());
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | 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... |