본문 바로가기
Programmers

[python] 무지의 먹방 라이브

by DylanMsK 2019. 9. 3.

문제 출처

무지의 먹방 라이브

 

풀이


def solution(food_times, k):
    times = {}
    for idx, time in enumerate(food_times):
        if time in times:
            times[time].append(idx)
        else:
            times[time] = [idx]

    len_foods = len(food_times)
    cycle = 0
    for time in sorted(times):
        if k - (len_foods*(time-cycle)) >= 0:
            k -= len_foods*(time-cycle)
            len_foods -= len(times[time])
            cycle += time-cycle
        else:
            k %= len_foods
            for i in times:
                if i >= time:
                    idx = times[i][0]
                    break
            for i in range(idx, len(food_times)):
                if food_times[i] >= time:
                    if k == 0:
                        return i+1
                    k -= 1
    return -1
    

'Programmers' 카테고리의 다른 글

[python] 완주하지 못한 선수  (0) 2019.09.03
[python] 추석 트래픽  (0) 2019.09.03
[python] 단어 변환  (0) 2019.09.01
[python] 네트워크  (0) 2019.09.01
[python] 타겟 넘버  (0) 2019.09.01