더이상 섞을 음식이 없고, 스코빌 지수가 K보다 낮다면 -1을 반환한다. (17~18번째 줄)
import heapq
def solution(scoville, K):
answer = 0
# make scoville list heap
heapq.heapify(scoville)
# while minimum of the heap is lower than K
while scoville[0] < K:
# mix 2 foods
a = heapq.heappop(scoville)
b = heapq.heappop(scoville)
heapq.heappush(scoville, a + (b * 2))
answer += 1
if len(scoville) == 1 and scoville[0] < K:
return -1
return answer