백준 11279 - 최대힙 (C++)

강승구·2023년 1월 24일
0

STL

#include <iostream>
#include <queue>

using namespace std;

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int N, x;
    cin >> N;
    
    priority_queue<int> pq;
    
    for(int i=0; i<N; i++){
        cin >> x;
        if(x==0){
            if(pq.empty()){
                cout << 0 << "\n";
            }else{
                cout << pq.top() << "\n";
                pq.pop();
            }
        }else{
            pq.push(x);
        }
    }
}
profile
강승구

0개의 댓글