Mechanic i has rank ranks[i]. Assigning x cars to a mechanic of rank r takes r * x * x minutes. The mechanics work at the same time, and you may distribute the cars cars among them however you choose. Return the minimum elapsed time until every car is repaired.
Example 1:
Input: ranks = [1,2]
cars = 4
Output: 8Explanation: Give two cars to each mechanic. They take 4 and 8 minutes, finishing in 8. Before minute 8, the first can finish at most two and the second at most one, so four cars cannot be completed sooner.
Example 2:
Input: ranks = [3]
cars = 2
Output: 12Explanation: The only mechanic must repair both cars, taking 3 * 2 * 2 = 12 minutes.
Example 3:
Input: ranks = [2,2]
cars = 3
Output: 8Explanation: One mechanic repairs two cars and the other repairs one, taking 8 and 2 minutes. Before minute 8, each can finish at most one car, so 8 is minimal.
Constraints:
1 <= ranks.length <= 1000001 <= ranks[i] <= 1001 <= cars <= 1000000