-
Notifications
You must be signed in to change notification settings - Fork 1
/
p11279.java
33 lines (32 loc) · 990 Bytes
/
p11279.java
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
import java.util.*;
import java.io.*;
public class p11279 {
static class PQ implements Comparable<PQ>{
int n;
public PQ(int n) {
this.n = n;
}
public int compareTo(PQ o) {
return o.n - n;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
PriorityQueue<PQ> pq = new PriorityQueue<>();
StringBuilder sb = new StringBuilder();
while (n-- > 0) {
int cal = Integer.parseInt(br.readLine());
if (cal == 0) {
if (pq.size() != 0) {
sb.append(pq.poll().n).append("\n");
} else {
sb.append(0).append("\n");
}
} else {
pq.offer(new PQ(cal));
}
}
System.out.println(sb.toString());
}
}