[백준] 11279번 최대 힙 C++

semi·2022년 8월 3일
0

coding test

목록 보기
29/57

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

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

0개의 댓글