# ★☆☆☆☆ 더 맵게

# 구현코드

import java.util.PriorityQueue;

class Solution {
    public int solution(int[] scoville, int K) {
        int answer = 0;

        PriorityQueue<Integer> minHeap = new PriorityQueue<>();

        for(int i = 0 ; i < scoville.length; i++){
            minHeap.add(scoville[i]);
        }

        while(minHeap.peek() < K){
            answer ++;
            int first = minHeap.remove();
            int second = minHeap.remove();
            int newSpicy = first + 2*second;

            if(minHeap.size() == 0)
                if(newSpicy < K)
                    return -1;
                else
                    return answer;

            minHeap.add(newSpicy);
        }

        return answer;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30