-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ11286.java
More file actions
37 lines (33 loc) · 979 Bytes
/
BOJ11286.java
File metadata and controls
37 lines (33 loc) · 979 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
36
37
package ¹éÁØ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
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> queue = new PriorityQueue<>(new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
if(Math.abs(o1) > Math.abs(o2)) {
return Math.abs(o1) - Math.abs(o2);
}
else if(Math.abs(o1) == Math.abs(o2)) {
return o1 - o2;
}
else {
return -1;
}
}
});
for(int i = 0; i < N; i++) {
int Num = Integer.parseInt(br.readLine());
if(Num == 0) {
if(queue.isEmpty()) System.out.println("0");
else System.out.println(queue.poll());
}
else queue.add(Num);
}
}
}