ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 42891 |
문제명 | 무지의 먹방 라이브 |
레벨 | Level 4 |
분류 |
정렬 |
시간복잡도 | O(nlogn) |
인풋사이즈 | n <= 200,000 |
사용한 언어 | Python |
해결날짜 | 2020/12/21 |
"""Solution code for "Programmers 42891. 무지의 먹방 라이브".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/42891
- Solution link: http://www.teferi.net/ps/problems/programmers/42891
"""
def solution(food_times, k):
answer = -1
food_count = len(food_times)
time_and_nums = sorted((t, i) for i, t in enumerate(food_times))
is_remaining = [True] * food_count
remaining_food_count = food_count
remaining_time = k
prev_time = 0
for cur_time, num in time_and_nums:
spent_time = remaining_food_count * (cur_time - prev_time)
if spent_time > remaining_time:
remaining_foods = [i for i in range(food_count) if is_remaining[i]]
answer = remaining_foods[remaining_time % remaining_food_count] + 1
break
is_remaining[num] = False
remaining_food_count -= 1
remaining_time -= spent_time
prev_time = cur_time
return answer