페이지

11279번: 최대 힙

https://www.acmicpc.net/problem/11279


$O(n\lg n)$


#include<cstdio>
#include<queue>
using namespace std;
priority_queue<int> pq;
int n, x;
int main() {
    for (scanf("%d", &n); n--;) {
        scanf("%d", &x);
        if (x) pq.push(x);
        else if (pq.empty()) puts("0");
        else printf("%d\n", pq.top()), pq.pop();
    }
    return 0;
}

댓글 없음 :

댓글 쓰기