import random
x = 2
y = 5
a = [random.randint(1,20) for _ in range(15)]
a.insert(0, 0)
a.append(0)
te = [0]*len(a)
print(a)
deq = []
for i in range(x, len(a)):
if deq and i-deq[0] >= y:
deq.pop(0)
while deq and te[deq[-1]] <= te[i-x]:
deq.pop()
deq.append(i-x)
imax = deq[0]
te[i] = a[i] + te[imax]
print(i, deq, te[i])