문제 링크: https://www.acmicpc.net/problem/1927
단순히 heap이 어떻게 c++에서 쓰여지는 지 볼 수 있는 문제였다.
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
priority_queue<int, vector<int>, greater<int> > heap;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, temp;
cin >> N;
for(int i = 0 ; i < N ; i++){
cin >> temp;
if(temp != 0) heap.push(temp);
if(temp == 0){
if(!heap.empty()){
cout << heap.top() << "\n";
heap.pop();
}
else{
cout << "0\n" ;
}
}
}
}