#include "bits/stdc++.h"
using namespace std;
#define SZ(s) (int)s.size()
#define ll long long
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector <ll> a(n), b, p(2*n+1,0);
for(int i = 0; i < n; i++){
cin >> a[i];
b.push_back(a[i]);
}
for(auto i : a) b.push_back(i);
ll ans = 0, k = (n+1)/2, s = 0;
multiset <ll> st;
p[0] = b[0];
for(int i = 1; i < 2*n; i++){
p[i] = p[i-1] + b[i];
}
for(int i = k-1; i < 2*n; i++){
st.insert(p[i]-((i-k < 0) ? 0 : p[i-k]));
if(SZ(st) == k){
ans = max(ans, *st.begin());
st.erase(st.find(p[i-k+1]-((i-2*k+1 < 0) ? 0 : p[i-2*k+1])));
}
}
cout << ans;
}
# | 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... |