-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42627.py
More file actions
29 lines (22 loc) · 761 Bytes
/
42627.py
File metadata and controls
29 lines (22 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# https://programmers.co.kr/learn/courses/30/lessons/42627?language=python3
import heapq
def solution(jobs):
answer = 0
complete_job_count = 0
priority_queue = []
time = 0
accumulate_works = -1
while complete_job_count < len(jobs):
for job in jobs:
if accumulate_works < job[0] <= time:
answer += time - job[0]
heapq.heappush(priority_queue, job[1])
if len(priority_queue) > 0:
answer += len(priority_queue) * priority_queue[0]
accumulate_works = time
time += heapq.heappop(priority_queue)
complete_job_count += 1
else:
time += 1
return answer // len(jobs)
print(solution([[0, 3], [1, 9], [2, 6]]))