-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj11286.java
More file actions
35 lines (30 loc) · 998 Bytes
/
boj11286.java
File metadata and controls
35 lines (30 loc) · 998 Bytes
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class boj11286 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
PriorityQueue<Integer> q = new PriorityQueue<>((o1, o2) -> {
int abs1 = Math.abs(o1);
int abs2 = Math.abs(o2);
if (abs1 == abs2) {
return o1 > o2 ? 1 : -1;
}
return abs1 - abs2;
});
for (int i = 0; i < N; i++) {
int num = Integer.parseInt(br.readLine());
if (num == 0) {
if (q.isEmpty()) {
System.out.println("0");
} else {
System.out.println(q.poll());
}
} else {
q.add(num);
}
}
}
}