Submission #532228

# Submission time Handle Problem Language Result Execution time Memory
532228 2022-03-02T14:14:28 Z pokmui9909 Candies (JOI18_candies) C++17
0 / 100
1 ms 444 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define x first
#define y second
ll N;
ll A[200005];
ll L[200005];
ll R[200005];
ll Del[200005];

int main(){
    cin.tie(0) -> sync_with_stdio(false);

    cin >> N;
    priority_queue<pair<ll, ll>> PQ;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        PQ.push({A[i], i});
        L[i] = i - 1, R[i] = i + 1;
    }
    ll ans = 0;
    for(int i = 1; i <= (N + 1) / 2; i++){
        while(Del[PQ.top().y]) PQ.pop();
        pair<ll, ll> T = PQ.top(); PQ.pop();
        ans += T.x;
        cout << ans << '\n';
        Del[L[T.y]] = Del[R[T.y]] = 1;
        A[T.y] = A[L[T.y]] + A[R[T.y]] - A[T.y];
        L[T.y] = L[L[T.y]], R[T.y] = R[R[T.y]];
        R[L[T.y]] = T.y, L[R[T.y]] = T.y;
        PQ.push({A[T.y], T.y});
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -