Loading...
Loading...
Loading...
A van can carry a total weight of W. There are N parcels, each with a weight and a delivery value. Each parcel is taken once or left. Print the largest total value that fits.
Example
Input
3 8 3 30 4 50 5 60
Output
90
Weights 3 and 5 give 90.
Try the problem first. Open one hint at a time.
Let best[w] be the greatest value with weight limit w. Each parcel either stays out or adds its value.
Process parcels one at a time and loop the weight from W down to the parcel weight.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor