Submission #98182

# Submission time Handle Problem Language Result Execution time Memory
98182 2019-02-21T08:01:35 Z onjo0127 Candies (JOI18_candies) C++11
0 / 100
3 ms 512 KB
#include <bits/stdc++.h>
using namespace std;

long long A[200009];
int L[200009], R[200009];
bool chk[200009];

int main() {
    int N; scanf("%d",&N);
    priority_queue<pair<long long, int> > pq;
    for(int i=1; i<=N; i++) {
        scanf("%d",&A[i]);
        pq.push({A[i], i});
        L[i] = i-1; R[i] = i+1;
    }
    pq.push({-1LL * 1e18, 0}); R[0] = 1;
    pq.push({-1LL * 1e18, N+1}); L[N+1] = N;
    long long ans = 0;
    for(int i=1; i<=(N+1)/2; i++) {
        long long v; int id;
        while(1) {
            tie(v, id) = pq.top(); pq.pop();
            if(!chk[id]) break;
        }
        ans += v; printf("%lld\n",ans);
        A[id] = A[L[id]] + A[R[id]] - A[id];
        pq.push({A[id], id});
        chk[L[id]] = chk[R[id]] = 1;
        L[id] = L[L[id]]; R[id] = R[R[id]];
        R[L[id]] = id; L[R[id]] = id;
    }
    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:12:25: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d",&A[i]);
                    ~~~~~^
candies.cpp:9:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int N; scanf("%d",&N);
            ~~~~~^~~~~~~~~
candies.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&A[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -