20 lines
587 B
Java
20 lines
587 B
Java
import java.util.*;
|
|
|
|
public class _11279{
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
int N = sc.nextInt();
|
|
PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
|
|
for(int i=0; i<N; i++){
|
|
int input = sc.nextInt();
|
|
if(input==0){
|
|
if(maxHeap.isEmpty()) System.out.println(0);
|
|
else System.out.println(maxHeap.poll());
|
|
}
|
|
else {
|
|
maxHeap.offer(input);
|
|
}
|
|
}
|
|
sc.close();
|
|
}
|
|
} |