[ PS / Python ] 42627. 디스크 컨트롤러

박제현·2024년 2월 10일
0

코딩테스트

목록 보기
20/101
post-thumbnail

풀이.

코드.

def solution(jobs):
    import heapq

    jobs.sort()
    count, last = 0, -1
    wait = []
    time = jobs[0][0]
    length = len(jobs)
    answer = 0

    while count < length:
        for s, t in jobs:
            if last < s <= time:
                heapq.heappush(wait, (t, s))
        if len(wait) > 0:
            last = time
            term, start = heapq.heappop(wait)
            count += 1
            time += term
            answer += (time - start)
        else:
            time += 1

    return answer // count

profile
닷넷 새싹

0개의 댓글