-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.cpp
More file actions
47 lines (47 loc) · 1.12 KB
/
11286.cpp
File metadata and controls
47 lines (47 loc) · 1.12 KB
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
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,x;
vector<int> ans;
priority_queue<int,vector<int>> pqM;
priority_queue<int,vector<int> , greater<int> > pqP;
cin>>n;
while(n--){
cin>>x;
if(x==0){
if(pqP.empty()&&pqM.empty()){
ans.push_back(0);
}else if(pqP.empty()){
ans.push_back(pqM.top());
pqM.pop();
}else if(pqM.empty()){
ans.push_back(pqP.top());
pqP.pop();
}else{
if(pqP.top()<abs(pqM.top())){
ans.push_back(pqP.top());
pqP.pop();
}else{
ans.push_back(pqM.top());
pqM.pop();
}
}
}else{
if(x>0){
pqP.push(x);
}else{
pqM.push(x);
}
}
}
for(int z: ans){
cout<<z<<"\n";
}
}