Find the minimum time needed for a group of mechanics to repair all cars, where each mechanic's repair speed depends on their rank.
Problem
You are given an array of mechanic ranks and an integer cars. Each mechanic with rank r needs r * n^2 minutes to repair n cars.
All mechanics can work in parallel, and each mechanic may repair any nonnegative number of cars. Determine the minimum time required to repair at least cars cars in total.
Goal
Return the smallest integer time t such that the mechanics can collectively finish repairing all cars within t minutes.
Input Format
ranks: an array of positive integers, whereranks[i]is the rank of mechanicicars: a positive integer
The exact platform signature may vary, but the core input is the ranks array and the number of cars.
Output Format
- Return the minimum integer time needed to repair at least
carscars.
Constraints
- Each mechanic with rank
rcan repairncars inr * n^2minutes. - Mechanics work independently and in parallel.
- The answer fits in 64-bit signed integer range.
- Use the smallest feasible time.
Example 1
Input
ranks = [4, 2, 3, 1], cars = 10
Output
16
Explanation
In 16 minutes, the mechanics can repair at least 10 cars in total. Any smaller time is not enough.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.