/ ALGORITHM

프로그래머스 - 더 맵게

image-20230121204833195

from heapq import heapify, heappop, heappush
def solution(scoville, K):
    answer = 0
    heapify(scoville)
    
    while len(scoville)>1:
        if scoville[0]>=K:
            return answer

        first = heappop(scoville)
        second = heappop(scoville)
        heappush(scoville,first+2*second)
        answer+=1
        
    if scoville[0]>=K:
        return answer
    return -1