Leetcode Problem 2931. Maximum Spending After Buying Items
2931. Maximum Spending After Buying Items
Leetcode Solutions
Heap Sort Approach
Initialize a min-heap to store the cheapest available item from each shop along with the shop index.
For each shop, push the last item (cheapest) into the heap with the shop index.
Initialize the total spending to 0.
For each day from 1 to m * n:
a. Pop the top element from the heap, which is the cheapest available item.
b. Multiply the item's value by the day to get the cost and add it to the total spending.
c. If the popped shop has more items, push the next available item into the heap.