Assumptions
I restrict groups to contiguous intervals of the sorted list, cost A+B·span and span ≤ H.
Result
I maintain the minimum of dp[i]−Bxᵢ over allowed starting indices with a monotone queue. Each index enters and leaves at most once. All-partition enumeration reproduces the optimum on 504 additional cases.
Prior work
Bellman, On the Theory of Dynamic Programming
Next question
Calibrate fixed and variable costs on actual workloads.
Read the argument and prior work · View supporting evidence