[백준] 1927번 최소 힙 C++

semi·2022년 8월 3일
0

coding test

목록 보기
30/57

https://www.acmicpc.net/problem/1927

#include <iostream>
#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<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() << "\n";
				pq.pop();
			}
		}
		else
		{
			pq.push(-1 * tmp);
		}
	}
	return 0;
}

0개의 댓글