https://www.acmicpc.net/problem/11279
// 11279번 : 최대 힙
#include <iostream>
#include <algorithm>
#include <queue>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
int N, x;
priority_queue<int> pq;
int main()
{
fastio;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> x;
if (x == 0)
{
if (pq.empty())
printf("0\n");
else
{
printf("%d\n", pq.top());
pq.pop();
}
}
else
pq.push(x);
}
}
C++로 언어를 바꾸면서 STL 활용법에 대해 공부중이다.
오늘은 우선순위 큐(힙)의 STL을 어떻게 활용하는지에 대한 문제를 풀었다.