백준 알고리즘 11279번 : 최대 힙

Zoo Da·2021년 7월 3일
0

백준 알고리즘

목록 보기
92/337
post-thumbnail

링크

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

Sol) 우선 순위 큐

// 11279번 : 최대 힙

#include <iostream>
#include <algorithm>
#include <queue>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

int N, x;
priority_queue<int> pq;

int main()
{
    fastio;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        if (x == 0)
        {
            if (pq.empty())
                printf("0\n");
            else
            {
                printf("%d\n", pq.top());
                pq.pop();
            }
        }
        else
            pq.push(x);
    }
}

복기

C++로 언어를 바꾸면서 STL 활용법에 대해 공부중이다.
오늘은 우선순위 큐(힙)의 STL을 어떻게 활용하는지에 대한 문제를 풀었다.

profile
메모장 겸 블로그

0개의 댓글