728x90

나의 풀이
import heapq
def solution(jobs):
jobs.sort()
time, total, number = 0, 0, len(jobs)
waiting = []
while jobs or waiting:
while jobs and jobs[0][0] <= time:
heapq.heappush(waiting, (jobs[0][1], jobs[0][0]))
jobs.pop(0)
if waiting:
time += waiting[0][0]
total += time - heapq.heappop(waiting)[1]
else:
time += 1
return total // number
deque를 이용한 풀이
import heapq
def solution(jobs):
jobs.sort()
time, total, number = 0, 0, len(jobs)
waiting = []
while jobs or waiting:
while jobs and jobs[0][0] <= time:
heapq.heappush(waiting, (jobs[0][1], jobs[0][0]))
jobs.pop(0)
if waiting:
time += waiting[0][0]
total += time - heapq.heappop(waiting)[1]
else:
time += 1
return total // number반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] K번째수 (0) | 2022.06.03 |
|---|---|
| [프로그래머스/파이썬] 이중우선순위큐 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 더 맵게 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 주식가격 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 다리를 지나는 트럭 (0) | 2022.05.31 |