22 lines
614 B
Java
22 lines
614 B
Java
import java.util.*;
|
|
|
|
public class _11286{
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
PriorityQueue<Integer> absHeap = new PriorityQueue<>((a,b) -> {
|
|
if(Math.abs(a) == Math.abs(b)) {
|
|
return a - b;
|
|
}
|
|
return Math.abs(a) - Math.abs(b);
|
|
});
|
|
int N = sc.nextInt();
|
|
|
|
for(int i = 0; i<N; i++){
|
|
int op = sc.nextInt();
|
|
if(op==0) System.out.println(absHeap.isEmpty() ? 0 : absHeap.poll());
|
|
else absHeap.add(op);
|
|
}
|
|
|
|
sc.close();
|
|
}
|
|
} |