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;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;
int n, A[2*MX];
ll ans=0;
ll S[2*MX];
ll solve(int t){
int s=0, e=n;
while(s<e){
int m=(s+e+1)/2;
int ss=m, ee=n;
while(ss<ee){
int mm=(ss+ee)/2;
if(S[t+mm]-S[t+m]>=S[t+m]-S[t]) ee=mm;
else ss=mm+1;
}
if(S[t+ss]-S[t+m]>=S[t+m]-S[t] && S[t+n]-S[t+ss]>=S[t+m]-S[t]) s=m;
else e=m-1;
}
return S[t+s]-S[t];
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>A[i];
for(int i=1; i<=n; i++) A[i+n]=A[i];
for(int i=1; i<=2*n; i++) S[i]=S[i-1]+A[i];
for(int i=1; i<=n; i++){
ans=max(ans, solve(i-1));
}
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... |