SW Expert Academy/level 1
[프로그래머스] 디스크 컨트롤러
binaryJournalist
2022. 6. 17. 22:27
반응형
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
import heapq
def solution(jobs):
answer = 0
end = 0
index = 0
start = -1
hq = []
while len(jobs) > index:
for job in jobs:
if start < job[0] <= end:
heapq.heappush(hq, (job[1], job[0]))
if hq:
now = heapq.heappop(hq)
start = end
end += now[0]
answer += (end - now[1])
index += 1
else:
end += 1
return answer // len(jobs)
반응형