Skip to content
Decoder

Minimum Cost to Hire K Workers

Hard

Problem

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.

Example 1

Input
quality = [10, 20, 5], wage = [70, 50, 30], k = 2
Output
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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.