내 코드
package com.company;
import java.io.*;
import java.util.*;
public class Main {
static int N;
static PriorityQueue<Integer> pq = new PriorityQueue<>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
int x = 0;
for (int i = 0; i < N; i++) {
x = Integer.parseInt(br.readLine());
if (x == 0)
delete();
else
pq.add(x);
}
}
static void delete() {
if (pq.isEmpty())
System.out.println(0);
else
System.out.println(pq.poll());
}
}
'코딩테스트 > [백준] 코딩테스트 연습' 카테고리의 다른 글
플로이드 - 11404번 (0) | 2021.12.24 |
---|---|
쉬운 계단 수 - 10844번 (0) | 2021.12.03 |
0만들기 - 7490번 (0) | 2021.12.03 |
카드 섞기 -21315번 (0) | 2021.12.02 |
트리 순회 (0) | 2021.12.02 |