답안 #31578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31578 2017-08-30T01:52:38 Z ngkan146 Hacker (BOI15_hac) C++
0 / 100
0 ms 9828 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int sum = 0;
int a[500005],b[500005];
int dq[1000005], dqfront,dqback;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]), sum += a[i];
    for(int i=0;i<n/2;i++)
        b[0] += a[i];
    for(int i=1;i<n;i++)
        b[i] = b[i-1] - a[i-1] + a[(i+n/2-1+n)%n];
    for(int i=1;i<=n/2 + (n%2==1);i++){
        if (dqfront==dqback) dq[dqback++] = i;
        else{
            while(dqfront < dqback && b[dqback] < b[i]) --dqback;
            dq[dqback++]=i;
        }
    }

    int ans = 0;
    for(int i=0;i<n;i++){
        if (dq[dqfront] == i) dqfront++;
        //cout << b[dq.front()] << endl;
        ans = max(ans, sum - b[dq[dqfront]]);


        while(dqfront < dqback && b[dqback] < b[(i+n/2 + (n%2==1)+1)%n]) --dqback;
            dq[dqback++]=(i+n/2 + (n%2==1)+1)%n;
    }
    cout << ans;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:8:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
hac.cpp:10:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]), sum += a[i];
                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Incorrect 0 ms 9828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Incorrect 0 ms 9828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Incorrect 0 ms 9828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Incorrect 0 ms 9828 KB Output isn't correct
3 Halted 0 ms 0 KB -