-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.cpp
More file actions
52 lines (50 loc) · 1.22 KB
/
11286.cpp
File metadata and controls
52 lines (50 loc) · 1.22 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
48
49
50
51
52
#include <bits/stdc++.h>
#define FastIO\
ios_base::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
using namespace std;
int main(){
FastIO;
int n;
cin>>n;
priority_queue<int, vector<int>, greater<int>> pq;//양수 오름차순
priority_queue<int> pq2;//음수 내림차순
vector<int> vec;
for(int i=0; i<n; i++){
int temp;
cin>>temp;
if(temp==0){
if(pq.empty()&&pq2.empty()){
vec.push_back(0);
}
else{
if(pq.empty()){
vec.push_back(pq2.top());
pq2.pop();
}
else if(pq2.empty()){
vec.push_back(pq.top());
pq.pop();
}
else if(pq.top()>=abs(pq2.top())){
vec.push_back(pq2.top());
pq2.pop();
}
else{
vec.push_back(pq.top());
pq.pop();
}
}
}
else if(temp>0){
pq.push(temp);
}
else{
pq2.push(temp);
}
}
for(auto i : vec){
cout<<i<<"\n";
}
}