💡코딩테스트/프로그래머스
[프로그래머스 | 파이썬 python] 디스크 컨트롤러
두_두
2023. 4. 18. 15:03
🌏문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
👽풀이
import heapq
def solution(jobs):
answer = 0
time = 0
start = -1
i = 0
heap = []
while i < len(jobs):
for j in jobs:
if start < j[0] <= time:
heapq.heappush(heap,[j[1],j[0]])
if len(heap)>0:
current = heapq.heappop(heap)
start = time
time += current[0]
answer += (time - current[1])
i += 1
else:
time += 1
return int(answer/len(jobs))
728x90