최소 힙
https://www.acmicpc.net/problem/1927
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
PriorityQueue<Integer> pQ = new PriorityQueue<>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
int input = Integer.parseInt(br.readLine());
if (input == 0) {
if (pQ.isEmpty()) {
System.out.println(0);
} else {
System.out.println(pQ.poll());
}
} else {
pQ.offer(input);
}
}
}
}
10분