Skip to content

Minimum Cost to Hire K Workers

HardHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.

There are n workers. Worker i has a work quality quality[i] and a minimum wage expectation wage[i]. You want to hire exactly k workers as a group, under two rules:

  • Everyone in the group is paid in proportion to their quality: if one worker has twice the quality of another, they are paid twice as much.
  • Everyone is paid at least their minimum wage.

Return the least total money needed to hire such a group. Answers within 10^-5 of the true value are accepted.

quality = [10, 20, 5], wage = [70, 50, 30], k = 2  →  105.0

Hire workers 0 and 2: pay 70 and 35. Worker 2's pay is half of worker 0's because their quality is half, and both meet their minimum.

Constraints

  • 1 <= k <= n <= 10^4
  • 1 <= quality[i], wage[i] <= 10^4