코딩문제풀이/프로그래머스
[Python] 무지의 먹방
코딩하는 포메라니안
2021. 9. 10. 15:51
1. 문제
2. 풀이 과정
from collections import Counter
def solution(food_times, k):
food_num = len(food_times) #현재 음식 개수
counting = Counter(food_times) #시간별 음식 개수
time_list = list(counting.keys()) #시간 목록
time_list.sort()
pre_time = 0
for time in time_list:
if k <= (time-pre_time)*food_num:
#이전 시간< 답 <=현재 시간
now_time = k//food_num
k -= now_time*food_num
for idx, t in enumerate(food_times, start = 1):
if t >= pre_time+now_time+1:
if k == 0:
return idx
k -= 1
#다음 time까지 걸린 시간 * 지금 남은 음식 수
k -= (time-pre_time)*food_num
#해당 시간의 음식은 다 먹은 것으로 빼준다.
food_num -= counting[time]
pre_time = time
return -1