라이브러리에 있는 우선순위 큐를 활용한다. 라이브러리의 우선순위 큐는 최대 힙이 기본이므로 그대로 사용해주면 된다.
우선순위 큐가 비어있을 때 제거하는 연산은 0을 출력해준다.
//백준 11279, 최대 힙
#include <iostream>
#include <queue>
int main (){
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::priority_queue<int> pq;
int N, x;
std::cin >> N;
while(N--){
std::cin >> x;
if(x == 0){
if(pq.empty()) std::cout << 0 << '\n';
else{
std::cout << pq.top() << '\n';
pq.pop();
}
}
else{
pq.push(x);
}
}
return 0;
}
이거 풀 때 백준 서버가 맛이 가버려서 계속 컴파일 에러가 났다... 뭐가 문제인지 한참 찾은...