import heapq
def solution(jobs):
answer = 0
time = 0
ready = []
idx = 0
jobs.sort()
n = len(jobs)
isReady = [False] * n
while idx < n:
for i in range(n):
if (not isReady[i]) and jobs[i][0] <= time:
heapq.heappush(ready, (jobs[i][1],jobs[i][0]))
isReady[i] = True
if ready:
a, b= heapq.heappop(ready)
time += a
answer += time - b
print(answer)
idx += 1
else:
time +=1
answer = answer // n
return answer