Minimum Cost to Hire K Workers
Real-world version: Cheapest Crew Under a Fair RateThe statement here is our own: the same inputs, outputs and technique.
A depot may hire from n fitters. Fitter i works at output output[i] and will not work below a pay floor of floor[i].
Exactly k fitters are hired, and the depot must pay in proportion to output: if two hired fitters have outputs a and b, their pay must be in the ratio a to b. Every hired fitter must also be paid at least their own floor.
Return the least total pay that hires k fitters. An answer within 1e-5 of the true value is accepted.
Examples
Example 1
- Input
- output = [10, 20, 5], floor = [70, 50, 30], k = 2
- Output
- 105.0
Hiring the second and third fitters means a rate of at least 6 per unit of output, since the third demands 30 for an output of 5, and their outputs of 20 and 5 come to 25, for a total pay of 150.
Example 2
- Input
- output = [4], floor = [8], k = 1
- Output
- 8.0
The only fitter must be hired and demands 8, which is a rate of 2 per unit of output.
Example 3
- Input
- output = [2, 4, 6, 8], floor = [1, 1, 1, 1], k = 4
- Output
- 10.0
All four must be hired. The fitter with output 2 demands the highest rate, half a unit of pay per unit of output, and the outputs come to 20.
Constraints
- 1 <= output.length <= 10^4
- output.length == floor.length
- 1 <= k <= 10000
- k is at most output.length
- 1 <= output[i] <= 10^4
- 1 <= floor[i] <= 10^4
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def cheapest_crew(output: list[int], floor: list[int], k: int) -> float:public double cheapestCrew(int[] output, int[] floor, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy
- Meeting Rooms IIReal-world version: Peak Charging Bay DemandMedium
- Task SchedulerReal-world version: Press Die CooldownMedium
- Maximum Number of Events That Can Be AttendedReal-world version: Most Inspections BookedMedium