Loading...
Loading...
You are given an integer array rates, where rates[i] is the rate of the i-th worker. A worker with rate r that is assigned n units of work finishes all of them at time r * n * n (a lower rate means a faster worker). A worker assigned no work finishes at time 0.
You are also given an integer units, the total amount of work to complete.
Each unit of work is assigned to exactly one worker. All workers start at time 0 and work at the same time, so the work is complete when the last worker finishes. Return the minimum time at which at least units units of work can be complete.
Input: rates = [4,2,3,1], units = 10
Output: 16
Explanation:
- The first worker (rate 4) completes two units in 4 * 2 * 2 = 16 time units.
- The second worker (rate 2) completes two units in 2 * 2 * 2 = 8 time units.
- The third worker (rate 3) completes two units in 3 * 2 * 2 = 12 time units.
- The fourth worker (rate 1) completes four units in 1 * 4 * 4 = 16 time units.
The last worker finishes at time 16, and no assignment of the 10 units finishes earlier.
Input: rates = [5,1,8], units = 6
Output: 16
Explanation:
- The first worker (rate 5) completes one unit in 5 * 1 * 1 = 5 time units.
- The second worker (rate 1) completes four units in 1 * 4 * 4 = 16 time units.
- The third worker (rate 8) completes one unit in 8 * 1 * 1 = 8 time units.
The last worker finishes at time 16, and no assignment of the 6 units finishes earlier.
rates.length ≤105rates[i] ≤100units ≤106