코딩테스트/백준
[실1] 11286 - 절대값 힙
ShovelingLife
2022. 6. 21. 12:22
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
#define y first
#define x second
int main()
{
using pq_type = pair<int, int>;
cin.sync_with_stdio(0);
cin.tie(0);
priority_queue<pq_type, vector<pq_type>, greater<pq_type>> q;
int n; cin >> n;
for (int i = 0; i < n; i++)
{
int val = 0; cin >> val;
if (val != 0)
q.push({ abs(val), val });
else
{
if (q.empty())
cout << "0" << endl;
else
{
cout << q.top().x << endl;
q.pop();
}
}
}
}