Greedy Algorithms8 sections · 316 units
Open in Course

Hire Workers - The Idea

The ratio determines cost

If you pick a worker with ratio rr, all workers in your group must be paid at ratio at least rr (to meet everyone's minimum wage). Sort workers by ratio.

For each worker, consider them as the "captain" who sets the payment ratio. The total cost is their ratio times the total quality of the group.

To minimize cost with a fixed ratio, you want minimum total quality. Use a max-heap to track the kk workers with smallest quality among those with ratio \leq captain's ratio.