코딩,안되면 될때까지

무지의 먹방 라이브 본문

프로그래머스/프로그래머스-파이썬

무지의 먹방 라이브

soo97 2022. 2. 26. 13:48
728x90
반응형

<문제>

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

 

코딩테스트 연습 - 무지의 먹방 라이브

 

programmers.co.kr

<코드>

-파이썬-

import heapq
def solution(food_times, k):
    if sum(food_times)<=k:
      return -1
    q=[]
    for i in range(len(food_times)):
      heapq.heappush(q,(food_times[i],i+1))
    sum_value = 0
    previous = 0
    length = len(food_times)
    while sum_value+((q[0][0]-previous)*length)<=k:
      now = heapq.heappop(q)[0]
      sum_value +=(now-previous)*length
      length-=1
      previous = now
    result = sorted(q,key=lambda x:x[1])
    return result[(k-sum_value)%length][1]
728x90
반응형

'프로그래머스 > 프로그래머스-파이썬' 카테고리의 다른 글

[프로그래머스]-자물쇠와 열쇠  (45) 2022.03.15
[프로그래머스]-괄호변환  (4) 2022.03.12
조이스틱  (0) 2022.02.26
타겟넘버  (0) 2022.02.26
2.오픈채팅방  (0) 2022.01.13
Comments