11279번: 최대 힙

myeongrangcoding·2023년 12월 27일
0

백준

목록 보기
40/47

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

풀이

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(false);
	//freopen("input.txt", "rt", stdin);

	int N{};
	cin >> N;

	priority_queue<int> pQ;

	int Integer{};
	for (int i{}; i < N; ++i)
	{
		cin >> Integer;

		if (Integer)
		{
			pQ.push(Integer);
		}
		else
		{
			if (pQ.empty())
			{
				cout << 0 << '\n';
			}
			else
			{
				cout << pQ.top() << '\n';
				pQ.pop();
			}
		}
	}

	return 0;
}
profile
명랑코딩!

0개의 댓글