답안 #126424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126424 2019-07-07T17:14:00 Z Vardanyan Hacker (BOI15_hac) C++14
0 / 100
2 ms 376 KB
#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;
            }
   //         cout<<as<<" ";
        }
     //   cout<<endl;
        ans = max(ans,mx2);
    }
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -