import java.util.PriorityQueue;
public class NUM42626 {
public static void main(String[] args) {
int[] scoville = {1, 2, 3, 9, 10, 12};
int K = 7;
System.out.println(solution(scoville, K));
}
public static int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> scovs = new PriorityQueue();
for(int s : scoville) { scovs.offer(s); }
while(scovs.peek() < K) {
if(scovs.size() == 1 && scovs.peek() < K) { answer = -1; break; }
scovs.offer(scovs.poll() + scovs.poll() * 2);
answer++;
}
return answer;
}
}
*다른 분들의 코드를 참고하여 작성했습니다