[프로그래머스LV2]더 맵게

박상준·2022년 8월 29일
0

코딩테스트

목록 보기
2/19
# 섞은 음식의 스코빌 지수 = 가장 맵지 않은 음식의 스코빌 지수 + (두 번째로 맵지 않은 음식의 스코빌 지수 * 2)
import heapq


def solution(scoville, K):
    answer = 0
    heapq.heapify(scoville)
    
    while True:
        print(f"scoville : {scoville}")
        if scoville[0] >= K:
            break
        if len(scoville) <= 1:
            return -1
        answer += 1
        small = heapq.heappop(scoville)
        small2 = heapq.heappop(scoville)
        snum = small + (small2 * 2)
        
        heapq.heappush(scoville, snum)
    
    return answer


print(solution([1, 1], 7))
profile
이전 블로그 : https://oth3410.tistory.com/

0개의 댓글