1927번: 최소 힙

myeongrangcoding·2023년 12월 5일
0

백준

목록 보기
11/47

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

구현 아이디어 0분 구현 2분

풀이

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

using namespace std;

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

    priority_queue<int> pQ;

    int N{}, x{};
    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        cin >> x;
        if (x == 0)
        {
            if (pQ.empty())
            {
                cout << 0 << '\n';
            }
            else
            {
                cout << -pQ.top() << '\n';
                pQ.pop();
            }
        }
        else
        {
            pQ.push(-x);
        }
    }

    return 0;
}
profile
명랑코딩!

0개의 댓글