import heapq

def solution(scoville, K):
    answer, min_s = 0, -1
    heapq.heapify(scoville)
    
    while min_s<K and scoville:
        if min_s>=0: heapq.heappush(scoville, min_s) 
        a, b = heapq.heappop(scoville), heapq.heappop(scoville)*2
        if a>=K: return 0
        heapq.heappush(scoville, a+b)
        min_s = heapq.heappop(scoville)
        if not scoville and min_s<K: return -1 
        answer += 1
        
    return answer

0개의 댓글