https://www.acmicpc.net/problem/11286
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, tmp;
priority_queue<pair<int, int>> pq;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> tmp;
if (tmp == 0)
{
if (pq.empty())
cout << "0\n";
else
{
cout << -1 * pq.top().second << "\n";
pq.pop();
}
}
else
{
pq.push({ -1 * abs(tmp), -1 * tmp });
}
}
return 0;
}