Rylah's Study & Daily Life
[SWEA/C++] 2930. 힙 본문
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV-Tj7ya3jYDFAXr
BOJ의 최소 힙과 문제가 유사하다.
https://www.acmicpc.net/problem/1927
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
39
40
41
42
43
44
45
46
47
48
49
|
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int testCase;
cin >> testCase;
for (int t = 1; t <= testCase; t++)
{
priority_queue<int, vector<int>, less<>> pq;
int n;
cin >> n;
vector<int> res;
for (int i = 0; i < n; i++)
{
int cmd;
cin >> cmd;
switch (cmd)
{
case 1:
int input;
cin >> input;
pq.emplace(input);
break;
case 2:
if (pq.empty())
{
res.emplace_back(-1);
}
else
{
res.emplace_back(pq.top());
pq.pop();
}
break;
}
}
cout << "#" << t << " ";
for (auto& e : res)
cout << e << " ";
cout << "\n";
}
return 0;
}
|
cs |
'SW Expert Academy' 카테고리의 다른 글
[SWEA/C++] 13547. 팔씨름 (0) | 2022.04.04 |
---|