Objets/Documentation
ancres.py
Programme ou résultat du contrôle reproductible dans le dossier lots.
Télécharger ↓"""Optimal contiguous query batches with a bounded span, versus exhaustive partitions."""
from collections import deque
from itertools import combinations_with_replacement
import json
def optimal(points,a,b,cap):
dp=[0]
queue=deque()
for j,x in enumerate(points):
value=dp[j]-b*x
while queue and queue[-1][1]>=value:queue.pop()
queue.append((j,value))
while x-points[queue[0][0]]>cap:queue.popleft()
dp.append(a+b*x+queue[0][1])
return dp[-1]