OilKnapsack reconstruction loop (type it)
OilKnapsack reconstruction loop (type it)
Answer
filled, b = [], b_star for i in range(n, 0, -1): if best[i][b] != best[i - 1][b]: # order i changed the value -> it was filled filled.append(i) b -= qty[i - 1] filled.reverse()
Trace back from the winning sold-amount b_star: a row that changed the optimal value is an order that was filled. Drop b by that order’s barrels and continue. O(n) total.