Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
If the total weight of the items is less than the capacity, then it is impossible to fill a bag.
The intended solution greedily chooses items to fill a bag.
Sort items in decreasing order of price/weight and greedily fill a bag. The main intuition behind the greedy strategy is that we try to take the highest possible price for 1 unit of weight.