Baekjoon 11279
최대 힙


QUESTION ❔



CODE ⌨️

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

class cmp
{
public:
	bool operator()(int a, int b)
	{
		return a < b;
	}
};

priority_queue<int, vector<int>, cmp> PQ;
vector<int> answer;

int N, x;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> x;

		if (x == 0)
		{
			if (PQ.empty())
			{
				answer.push_back(0);
			}
			else
			{
				answer.push_back(PQ.top());
				PQ.pop();
			}
		}
		else
		{
			PQ.push(x);
		}
	}

	for (int i = 0; i < answer.size(); i++)
	{
		cout << answer[i] << "\n";
	}

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

우선순위 큐(PQ) 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.