[SWEA] 2930 힙

Time Lapse :11min 58sec

2930.cpp

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
#include <iostream>
#include <queue>
using namespace std;

int main(int argc, char** argv) {
register int i, j;
int TC, repeat, num;
char cmd;
scanf("%d",&TC);
getchar();
for (i = 1; i<=TC; i++) {
scanf("%d",&repeat);
getchar();
printf("#%d ",i);
priority_queue<int, vector<int>, less<int>> pq;
for(j=0;j<repeat;j++){
cmd=getchar();
getchar();
switch (cmd){
case '1':
scanf("%d",&num);
getchar();
pq.push(num);
break;
case '2':
if(pq.empty()){
printf("-1 ");
}
else{
printf("%d ",pq.top());
pq.pop();
}
break;
default:
break;
}
}
printf("\n");
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/2930/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.