-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy path[11]_1.java
More file actions
35 lines (29 loc) · 723 Bytes
/
[11]_1.java
File metadata and controls
35 lines (29 loc) · 723 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
26
27
28
29
30
31
32
33
34
35
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// 자바(Java)에서는 기본적으로 우선순위 큐가 최소 힙(Min Heap)
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
ArrayList<Integer> result = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
if (x == 0) {
if (!pq.isEmpty()) {
result.add(pq.poll());
}
else {
result.add(0);
}
}
else {
pq.add(x);
}
}
for (int i = 0; i < result.size(); i++) {
System.out.println(result.get(i));
}
}
}