import heapq
def mix_food(min_food, next_food):
multi = 2
return min_food + next_food * multi
def solution(scovilles, K):
heap = []
min_food = 0
next_food = 0
mix = 0
for scoville in scovilles:
heapq.heappush(heap, scoville)
while True:
min_food = heapq.heappop(heap)
if(min_food >= K):
break
if(len(heap) == 0):
return -1
next_food = heapq.heappop(heap)
heapq.heappush(heap, mix_food(min_food, next_food))
mix += 1
return mix
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 직사각형 별찍기 (python) (0) | 2021.06.04 |
---|---|
[프로그래머스] 주식가격(python) (0) | 2021.06.04 |
[프로그래머스] 2016 (python) (0) | 2021.05.26 |
[프로그래머스] 제일 작은 수 제거하기(python) (0) | 2021.05.25 |
[프로그래머스] 문자열 내림차순으로 배치하기 (python) (0) | 2021.05.22 |
댓글