-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ11286.cpp
More file actions
41 lines (32 loc) · 739 Bytes
/
Q11286.cpp
File metadata and controls
41 lines (32 loc) · 739 Bytes
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
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct Compare {
bool operator()(int a, int b) {
if (abs(a) == abs(b))
return a > b; // 작은 값이 먼저 나오게 (minHeap)
return abs(a) > abs(b); // 절댓값 작은 게 먼저
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
int t;
cin>>t;
int n;
priority_queue<int, vector<int>, Compare> minHeap;
while(t--){
cin>>n;
if(n == 0) {
if(minHeap.empty()) cout<<0<<'\n';
else {
cout<<minHeap.top()<<'\n';
minHeap.pop();
}
}
else{
minHeap.push(n);
}
}
}