[프로그래머스] 더 맵게

 

문제

import heapq

def solution(scoville, K):
    answer = 0
    heapq.heapify(scoville)
    while True:
        if len(scoville) < 2:
            if scoville[0] >= K:
                return answer
            else:
                return -1
        else:
            tmp1 = heapq.heappop(scoville)
            tmp2 = heapq.heappop(scoville)
            if tmp1 >= K:
                return answer
            else:
                heapq.heappush(scoville, tmp1 + (tmp2*2))
            answer+=1
                
    return answer