-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.java
More file actions
51 lines (45 loc) · 1.02 KB
/
11286.java
File metadata and controls
51 lines (45 loc) · 1.02 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
import java.util.*;
import java.io.*;
public class Main {
static class absolute implements Comparable<absolute>{
int real;
int fake;
public absolute(int temp, int abs) {
super();
this.real = temp;
this.fake = abs;
}
@Override
public int compareTo(absolute s) {
if(this.fake < s.fake) {
return 1;
}else if(this.fake == s.fake) {
if(this.real < s.real) {
return 1;
}else if(this.real == s.real) {
return 0;
}
}
return -1;
}
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
PriorityQueue<absolute> pq = new PriorityQueue<>(Collections.reverseOrder());
for(int i=0;i<num;i++) {
int temp = sc.nextInt();
if(temp == 0) {
if(pq.isEmpty()) {
System.out.println(0);
}else {
absolute abb = pq.poll();
System.out.println(abb.real);
}
}else {
absolute abs = new absolute(temp, Math.abs(temp));
pq.add(abs);
}
}
}
}