OilKnapsack recurrence + objective (type it)
OilKnapsack recurrence + objective (type it)
Answer
best[0][0] = 0; best[0][b>=1] = -inf best[i][b] = max( best[i-1][b], # skip order i best[i-1][b - q_i] + p_i ) # fill order i, if q_i <= b profit = max over b of ( best[n][b] - s*(P - b) )
Four lines you should be able to reproduce cold for the project write-up: base case, the skip/fill recurrence, and the storage-adjusted objective scanned over every feasible sold-amount b.