728x90
반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine()," ");
int n = Integer.parseInt(st.nextToken()); // 과일의 갯수
int l = Integer.parseInt(st.nextToken()); // 초기 길이
PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
st = new StringTokenizer(br.readLine()," ");
for (int i = 0; i < n; i++) {
priorityQueue.add(Integer.parseInt(st.nextToken()));
}
while (!priorityQueue.isEmpty()){
int poll = priorityQueue.poll();
if(l >= poll){
l++;
}else{
break;
}
}
System.out.println(l);
}
}
728x90
반응형
'알고리즘 > 힙(우선순위큐)' 카테고리의 다른 글
[백준] 11286번 절대값 힙 #Java (0) | 2022.05.27 |
---|---|
[백준] 11279번 최대 힙 (0) | 2022.05.17 |
[백준] 1927번 최소 힙 #Java (0) | 2022.05.16 |