-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11286.cpp
44 lines (43 loc) · 1.04 KB
/
11286.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
41
42
43
44
#include<iostream>
#include<queue>
using namespace std;
int main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, order;
priority_queue<int>q;
priority_queue<int, vector<int>, greater<int>>qq;
cin >> n;
for(int i = 0; i < n; i++){
cin >> order;
if(order<0){
q.push(order);
}
else if(order>0){
qq.push(order);
}
else {
if(q.empty()&&qq.empty())
cout << '0' << '\n';
else if(q.empty()&&!qq.empty()){
cout << qq.top() << '\n';
qq.pop();
}
else if(!q.empty() && qq.empty()){
cout << q.top() << '\n';
q.pop();
}
else {
if((q.top())*(-1) <= qq.top()){
cout << q.top() << '\n';
q.pop();
}
else {
cout << qq.top() << '\n';
qq.pop();
}
}
}
}
}