최대 힙
최대 힙을 사용하기 위해 queue 자료구조를 사용하였다.
pop()은 최대값을 삭제할 뿐 최대값을 반환해주지는 않으므로 top()을 통해 최대값을 반환받은 후 pop()으로 제거해주었다.
#include<iostream>
#include<queue>
#include<string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
priority_queue<int>max_heap;
long long num;
int x;
cin >> num;
for (int i = 0;i < num;i++) {
cin >> x;
if (x == 0) {
if (max_heap.empty()) {
cout << 0<<"\n";
}
else {
cout << max_heap.top()<<"\n";
max_heap.pop();
}
}
else {
max_heap.push(x);
}
}
return 0;
}