История изменений
Исправление question4, (текущая версия) :
import sys, collections
ar = list(map(int, sys.stdin.read().split()))
size, npac = ar[0:2]
packets = [ar[lcv*2+2:lcv*2+4] for lcv in range(npac)]
queue = collections.deque()
log = [-1 for _ in range(npac)]
#tc = 0
t0 = 0
for pn in range(npac):
cparrival, cpduration = packets[pn]
# tc <= cparrival
while len(queue) > 0 and t0 + queue[0][0] <= cparrival :
d0, pn0 = queue.popleft()
t0 = t0 + d0 #tc
if queue:
log[queue[0][1]] = t0
#t0 = tc
#tc = cparrival
if len(queue) < size:
queue.append([cpduration, pn])
if len(queue) == 1:
log[pn] = cparrival
t0 = cparrival
#tc = t0
while queue:
d0, pn0 = queue.popleft()
log[pn0] = t0
t0 += d0
for p in log:
print(p)
На 10⁶ пакетов с буферами длиной до 1000 ускорение примерно вдвое.
Исходная версия question4, :
import sys, collections
ar = list(map(int, sys.stdin.read().split()))
size, npac = ar[0:2]
packets = [ar[lcv*2+2:lcv*2+4] for lcv in range(npac)]
queue = collections.deque()
log = [-1 for _ in range(npac)]
tc = 0
t0 = 0
for pn in range(npac):
cparrival, cpduration = packets[pn]
while len(queue) > 0 and tc <= cparrival:
d0, pn0 = queue[0][0], queue[0][1]
if t0 + d0 <= cparrival:
queue.popleft()
tc = t0 + d0
if queue:
log[queue[0][1]] = tc
t0 = tc
else:
break
tc = cparrival
if len(queue) < size:
queue.append([cpduration, pn])
if len(queue) == 1:
log[pn] = tc
t0 = tc
tc = t0
while queue:
d0, pn0 = queue[0][0], queue[0][1]
queue.popleft()
log[pn0] = tc
tc += d0
for p in log:
print(p)
На 10⁶ пакетов с буферами длиной до 1000 ускорение примерно вдвое.