[백준] 11286번 절댓값 힙 C++

semi·2022년 8월 3일
0

coding test

목록 보기
31/57

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;
}

0개의 댓글