-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
25 lines (21 loc) · 729 Bytes
/
Main.java
File metadata and controls
25 lines (21 loc) · 729 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
PriorityQueue<Integer> q = new PriorityQueue<Integer>();
for(int i=0; i<N; i++){
int x = Integer.parseInt(br.readLine());
if(x == 0){
if(!q.isEmpty()) {System.out.println(q.poll());}
else {System.out.println(0);}
} else {
q.offer(x);
}
}
br.close();
}
}