[프로그래머스] 무지의 먹방 라이브

이강혁·2025년 2월 13일
0

프로그래머스

목록 보기
90/92

https://school.programmers.co.kr/learn/courses/30/lessons/42891

import heapq

def solution(food_times, k):
    answer = -1
    hq = []
    for i in range(len(food_times)):
        heapq.heappush(hq, (food_times[i], i+1))      
    length = len(hq)
    pre = 0  
    while hq:
        diff = (hq[0][0] - pre) * length
        if diff <= k:
            k -= diff
            length -= 1
            pre, _ = heapq.heappop(hq)
        else:
            idx = k % length
            answer = hq[idx][1]
            break
    return answer
profile
사용자불량

0개의 댓글

관련 채용 정보