Submission #48411

# Submission time Handle Problem Language Result Execution time Memory
48411 2018-05-12T19:56:12 Z choikiwon Candies (JOI18_candies) C++17
0 / 100
3 ms 376 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MN = 200010;

int N;
ll A[MN];
int pre[MN], nxt[MN];
priority_queue<pair<ll, int> > pq;

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    for(int i = 0; i < N; i++) {
        pre[i] = i - 1;
        nxt[i] = i + 1;
        pq.push({ A[i], i });
    }

    ll sum = 0;
    for(int i = 1; i <= (N + 1) / 2; i++) {
        pair<ll, int> t = {-1, -1};
        while(!pq.empty()) {
            t = pq.top(); pq.pop();
            if(A[t.second] == t.first) break;
        }
        sum += t.first;
        printf("%lld\n", sum);

        A[t.second] = -A[t.second];
        if(pre[t.second] != -1) {
            A[t.second] += A[ pre[t.second] ];
            A[ pre[t.second] ] = -1e18;
            pre[t.second] = pre[ pre[t.second] ];
            if(pre[t.second] != -1) nxt[ pre[t.second] ] = t.second;
        }
        if(nxt[t.second] != N) {
            A[t.second] += A[ nxt[t.second] ];
            A[ nxt[t.second] ] = -1e18;
            nxt[t.second] = nxt[ nxt[t.second] ];
            if(nxt[t.second] != N) pre[ nxt[t.second] ] = t.second;
        }
        A[t.second] = max(A[t.second], (ll)-1e18);
        pq.push({ A[t.second], t.second });
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
candies.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &A[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -