-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.cpp
More file actions
49 lines (46 loc) · 1.16 KB
/
Copy path11286.cpp
File metadata and controls
49 lines (46 loc) · 1.16 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
// solved_1552kb_20ms_47729650_1156b
#include <cstdio>
#include <queue>
using namespace std;
priority_queue <int, vector <int>, less <int>> mi;
priority_queue <int, vector<int>, greater<int>> pl;
int main (){
int n, a;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &a);
if(a > 0){
pl.push(a);
}
else if (a < 0){
mi.push(a);
}
else{
if(!mi.empty()){
if(!pl.empty()){
int a = -1 * mi.top();
int b = pl.top();
if(a <= b){
printf("%d\n", -1*a);
mi.pop();
}
else{
printf("%d\n", b);
pl.pop();
}
}
else{
printf("%d\n", mi.top());
mi.pop();
}
}
else{
if(!pl.empty()){
printf("%d\n", pl.top());
pl.pop();
}
else printf("0\n");
}
}
}
}