Algorithm & SQL/BAEKJOON
백준 JAVA 14235 크리스마스 선물
YoonJong
2022. 8. 2. 16:13
728x90
반응형
package BAEKJOON.Silver.Ⅲ;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class NO14235 {
// 가치가 '큰' 선물부터 주기 때문에, 내림차순 정렬
static PriorityQueue<Integer> Q = new PriorityQueue<>(Collections.reverseOrder());
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int num = sc.nextInt();
if (num == 0) {
if (!Q.isEmpty()) {
System.out.println(Q.poll());
} else {
System.out.println(-1);
}
} else {
// 첫번째 입력값은 개수
for (int j = 0; j < num; j++) {
// num 만큼 입력받기
Q.offer(sc.nextInt());
}
}
}
}
}
728x90
반응형