Unlock, then take the best
transcript
An ad team has a starting budget. Campaigns need a budget before they start. Each campaign adds a gain when it ends. Reach the target with the fewest campaigns.
A campaign is allowed when its cost fits. Sort by cost, so they open in order. Push each allowed campaign into a heap. The heap holds only the allowed ones.
The budget is three. Only cost two fits. Run it, and the budget becomes six. Take the larger gain of six. Now twelve. Take the gain of ten, to twenty-two.
Each round spends one campaign. So pick the one that leaves the most budget. The cheapest campaign adds the least. It needs four campaigns on this list.
Take the same list and the same target. Largest gain needs three campaigns. Cheapest first needs four campaigns.
Sort so campaigns open in order. Keep the allowed ones in a heap. If the heap is empty, answer minus one. Full breakdown in the lecture.