-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.cpp
More file actions
46 lines (43 loc) · 1.07 KB
/
11286.cpp
File metadata and controls
46 lines (43 loc) · 1.07 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
#include<iostream>
#include<queue>
#include<stdio.h>
using namespace std;
int main(){
priority_queue<int> positive;
priority_queue<int> negative;
int N,x;
cin>>N;
for(int i=0;i<N;i++){
scanf("%d",&x);
if(x==0){
if(positive.empty()&&negative.empty()){
printf("0\n");
}
else if(positive.empty()){
printf("%d\n",negative.top());
negative.pop();
}
else if(negative.empty()){
printf("%d\n",-positive.top());
positive.pop();
}
else{
int pos=-positive.top();
int neg=-negative.top();
if(neg<=pos){
printf("%d\n",-neg);
negative.pop();
}
else{
printf("%d\n",pos);
positive.pop();
}
}
}
else if(x>0)
positive.push(-x);
else
negative.push(x);
}
return 0;
}