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;
using ll = long long;
const int inf = 1e9;
void solve(){
int n; cin >> n;
vector<int> p(n);
for(int i = 0; i < n; i ++) cin >> p[i];
int ans = 0;
for(int i = 1; i < n; i ++){
p[i] += p[i - 1];
}
auto get = [&](int l, int r)->int{
if(l > r){
return p[r] + p[n - 1] - (l ? p[l - 1] : 0);
}
return p[r] - (l ? p[l - 1] : 0);
};
multiset<int> st;
int k = (n + 1) / 2;
for(int i = 0; i < n; i ++){
for(int j = i; j < i + k; j ++){
int r = j % n;
int l = ((r - k + 1) % n + n) % n;
st.insert(get(l, r));
}
ans = max(ans, *st.begin());
break;
}
for(int i = 1; i < n; i ++){
int del = get(((i - k) % n + n) % n, i - 1);
int add = get(i, (i + k - 1) % n);
//cout << del << ' ' << add << endl;
st.erase(st.find(del));
st.insert(add);
ans = max(ans, *st.begin());
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int testcases = 1;
while(testcases --){
solve();
if(testcases) cout << '\n';
#ifdef LOCAL
else cout << '\n';
cout << "__________________________" << endl;
#endif
}
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... |