이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 500*1000+5;
int a[N];
int pref[N];
int n;
int getl(int st,int ed){
if(ed<=st) return pref[st]-pref[ed-1];
return pref[st]+(pref[n]-pref[ed-1]);
}
int getr(int st,int ed){
if(ed>=st) return pref[ed]-pref[st-1];
return (pref[n]-pref[st-1])+pref[ed];
}
int main(){
ios_base::sync_with_stdio(false);
cin>>n;
for(int i = 1;i<=n;i++){
cin>>a[i];
pref[i] = pref[i-1]+a[i];
}
int k = (n+1)/2;
int ans = 0;
for(int i = 1;i<=n;i++){
int mx1,mx2;
mx1 = mx2 = 0;
for(int l = 0;l<=k-1;l++){
int r = k-l-1;
int tl = i;
tl-=l;
if(tl<=0) tl = n-tl;
int as1 = getl(i,tl);
int tr = i;
tr+=r;
if(tr>n) tr = 1+(tr-n-1);
int as2 = getr(i,tr);
int as = as1+as2-a[i];
if(as>=mx1){
mx2 = mx1;
mx1 = as;
}
else if(as>mx2){
mx2 = as;
}
}
ans = max(ans,mx2);
}
cout<<ans<<endl;
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... |