Trains the technique from
LeetCode 857Minimum Cost to Hire K WorkersThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
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
The only fitter must be hired and demands 8, which is a rate of 2 per unit of output.
Example 3
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.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def cheapest_crew(output: list[int], floor: list[int], k: int) -> float:public double cheapestCrew(int[] output, int[] floor, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.