www.acmicpc.net/problem/11279

 

11279번: 최대 힙

첫째 줄에 연산의 개수 N(1≤N≤100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0이�

www.acmicpc.net

#include <iostream>
#include <queue>

using namespace std;

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

    int n;
    cin >> n;
    unsigned int data = 0;
    priority_queue<unsigned int> pq;       
    for(int i = 0 ; i < n ; i++)
    {
        cin >> data;
        if(data == 0)
        {
            if(pq.empty())                   
            {
                cout << 0 << '\n';
                continue;
            }
            cout << pq.top() << '\n';
            pq.pop();
        }
        else
        {
            pq.push(data);
        }
    }
}

 

[Approach]

1. 직접 구현해보기...로 하려다가 일단은 빠르게 우선순위 큐 사용해서 풀었다.

 

[Point]

1. 자료구조를 알고 있었다면 쉬운 문제. 모른다면 뭐 헤딩해야되는데 꼭 구현해볼 것. 자료구조별로! 다!!!!

'PS > BOJ' 카테고리의 다른 글

[백준] 5525.cpp : IOIOI  (0) 2020.07.04
[백준] 18870.cpp : 좌표 압축  (0) 2020.07.04
[백준] 5430.cpp : AC  (0) 2020.07.03
[백준] 1780.cpp : 종이의 개수  (0) 2020.07.03
[백준] 1541.cpp : 잃어버린 괄호  (0) 2020.07.03

+ Recent posts