24 lines
797 B
Python
24 lines
797 B
Python
def solution(jobs):
|
|
sorted_jobs = sorted(jobs)
|
|
print(sorted_jobs)
|
|
tick = 0
|
|
latency = 0
|
|
pending_jobs = []
|
|
for job in sorted_jobs:
|
|
request, task = job
|
|
while (tick < request) and (len(pending_jobs) > 0):
|
|
r, t = pending_jobs.pop(0)
|
|
tick = max(r, tick) + t
|
|
latency += tick - r
|
|
print('update tick', tick, 'latency', latency, 'pending_jobs', pending_jobs)
|
|
pending_jobs += [job]
|
|
pending_jobs = sorted(pending_jobs, key=lambda jobs: jobs[1])
|
|
print('pending_jobs', pending_jobs)
|
|
while len(pending_jobs) > 0:
|
|
r, t = pending_jobs.pop(0)
|
|
tick = max(r, tick) + t
|
|
latency += tick - r
|
|
print('update tick', tick, 'latency', latency)
|
|
|
|
return latency // len(jobs)
|