import java.util.PriorityQueue;
class Solution {
public int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> heap = new PriorityQueue<>();
for(int ascoville : scoville) {
heap.offer(ascoville);
}
while (heap.peek() <= K) {
if(heap.size()==1) return -1;
int a = heap.poll();
int b = heap.poll();
int result = a + (b*2);
heap.offer(result);
answer++;
}
return answer;
}
public static void main(String[] args) {
int[] scoville = {1,2,3,9,10,12};
int K = 7;
Solution st = new Solution();
System.out.println(st.solution(scoville,K));
}
}