https://www.acmicpc.net/problem/11279
우선순위 큐 자료구조를 이용하였다.
priority_queue를 이용하려면 #include <queue>
문을 써줘야 한다.
priority_queue<int, vector<int>, less<int>> max_heap;
우선순위 큐는 기본적으로 최대 힙을 구현하므로, 최대 힙을 사용할 때는 아래와 같이 써도 된다.
priority_queue<int> max_heap;
#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> heap;
while(n--){
cin >> x;
if(x) heap.push(x);
else if(heap.empty()) cout << "0\n";
else{
cout << heap.top() << "\n";
heap.pop();
}
}
return 0;
}