#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5+5;
int arr[MAXN],pref[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
for(int i = 1;i<=N;++i){
cin >> arr[i];
pref[i] = pref[i-1]+arr[i];
}
int len = (N+1)/2, ans = 0;
set<int> s; map<int,int> cnt; //if it is 0, delete it
for(int i = 1;i<=N;++i){
if(s.size()){
if(i-len-1 >= 0){
--cnt[pref[i-1]-pref[i-len-1]];
if(cnt[pref[i-1]-pref[i-len-1]] == 0){
s.erase(pref[i-1]-pref[i-len-1]);
}
}
}
if(i+len-1 <= N){
s.insert(pref[i+len-1]-pref[i-1]);
//cout << pref[i+len-1]-pref[i-1] << "\n";
++cnt[pref[i+len-1]-pref[i-1]];
}
else{
s.insert(pref[N]-pref[i-1]+pref[len-(N-i+1)]);
//cout << pref[N]-pref[i-1]+pref[len-(N-i+1)] << "\n";
++cnt[pref[N]-pref[i-1]+pref[len-(N-i+1)]];
}
ans = max(ans,(*s.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... |