본문 바로가기

백준

1927 최소 힙

날먹문제...

 

pq 사용해서 풀었다

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>

#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()

using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;

int     main()
{
	int n;
	scanf("%d", &n);

	priority_queue<int, vector<int>, greater<int> > pq;

	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);

		if (x != 0)
		{
			pq.push(x);
			continue;
		}

		if (pq.empty())
		{
			printf("0\n");
			continue;
		}

		printf("%d\n", pq.top());
		pq.pop();
	}

	return 0;
}

'백준' 카테고리의 다른 글

20125 쿠키의 신체 측정  (0) 2020.12.11
15970 화살표 그리기  (0) 2020.12.05
2607 비슷한 단어  (0) 2020.12.01
11660 구간 합 구하기 5  (0) 2020.11.24
20127 Y-수열  (0) 2020.11.24