Ezvor

2548. Maximum Price to Fill a Bag

MediumArray Preparing judge… LeetCode
ArrayGreedySorting

Hints

Hint 1
If the total weight of the items is less than the capacity, then it is impossible to fill a bag.
Hint 2
The intended solution greedily chooses items to fill a bag.
Hint 3
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.