안선생의 개발 블로그

C++ 11279 최대 힙 본문

백준

C++ 11279 최대 힙

안선생 2023. 2. 12. 16:53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
 
    int n; cin >> n;
    priority_queue<int> a;
    while (n--)
    {
        int input;
        cin >> input;
 
        if (input == 0)
        {
            if (!a.empty())
            {
                cout << a.top() << "\n";
                a.pop();
            }
            else
                cout << 0 << "\n";
        }
        else
            a.push(input);
    }
    return 0;
}
 
 

cs




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

 

11279번: 최대 힙

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

www.acmicpc.net

 

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

C++ 7568 덩치  (0) 2023.02.12
C++ 1927 최소힙  (0) 2023.02.12
C++ 2164 카드2  (0) 2023.02.11
C++ 백준 2846 5와 6의 차이  (0) 2023.02.11
C++ 1026 보물  (0) 2023.02.11