1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| def solution(jobs):
import heapq as hp
task_n = len(jobs)
hp.heapify(jobs)
dp = []
time = jobs[0][0]
answer = 0
for i in range(task_n):
while(jobs and jobs[0][0]<=time):
(t, d) = hp.heappop(jobs)
hp.heappush(dp, (d, t))
(d, t) = hp.heappop(dp)
answer += d + max(0, time - t)
time = d + max(time, t)
return answer//task_n
|