Ctrl K

Crew Paid by Skill

Hard
There are n candidates. Candidate i has skill skill[i] and refuses to work for less than min_pay[i]. You must hire exactly crew_size people so that: - everyone gets at least their minimum pay; - pay within the crew is proportional to skill: someone with twice the skill of a colleague earns twice as much. Return the smallest total amount the crew will cost. Answers within 10⁻⁵ of the true value are accepted.
Example 1
skill=[4, 2, 6], min_pay=[20, 6, 18], crew_size=2 → 24.0

Hire workers 1 and 2: both accept 3 per unit of skill, so they get 2·3 = 6 and 6·3 = 18, 24 in total. Any pair with worker 0 needs a rate of 5 and costs more.

Example 2
skill=[3, 1, 2], min_pay=[9, 1, 2], crew_size=3 → 18.0

Everyone is hired. Worker 0 asks for the highest rate, 3 per unit of skill, so the bill is 3·(3 + 1 + 2) = 18.

Example 3
skill=[5, 7, 3], min_pay=[10, 7, 9], crew_size=1 → 7.0
Constraints
  • 1 ≤ crew_size ≤ n ≤ 10⁴
  • n = len(skill) = len(min_pay)
  • 1 ≤ skill[i], min_pay[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsGrowing Capital Project by Project HardMost Orders by Their Deadlines HardNarrowest Range Touching Every List HardThe Slowest Sets the Squad's Pace HardScore Spread of Parcel Groups Hard
loading Python…
Input
skill=[4, 2, 6], min_pay=[20, 6, 18], crew_size=2
Expected
24.0

Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.