RipplingOA #5
Find Minimum Time
估计中等评测数据准备中,可先阅读题面
There are n processes to be executed, and the ith process has a size of processSize[i], where 1 ≤ i ≤ n. Also, there are m processors of different size capacity. The capacity of the ith processor is capacity[i] ( 1 ≤ i ≤ m ). A processor can process a task of size less than or equal to its capacity in 1 second, but it cannot execute processes whose size is greater than its capacity.
A processor can execute multiple processes one after the other, but needs to pause for 1 second after completing its current one. Multiple processors can work on different processes simultaneously.
Find the minimum time to execute all the processes or return -1 if there is no way to execute all the processes.
Function Description
Complete the function findMinimumTime in the editor.
findMinimumTime has the following parameters:
-
int[] processSize: an array of integers representing the sizes of processes
-
int[] capacity: an array of integers representing the capacities of processors Returns int: the minimum time to execute all the processes or-1if it is not possible
Example 1
Input:
processSize = [2, 5, 3]
capacity = [6, 2, 4]
Output:
1
Explanation: The optimal way to assign processes is to give:
- The first processor the second process
- The second processor the first process
- The third processor the third process All of them complete their processes in 1 second. Therefore, the minimum time required is 1 second.
Example 2
Input:
processSize = [1, 2, 3, 4, 6]
capacity = [4, 1, 4]
Output:
3
Explanation: Assign the second and third process to the first processor. It completes the first process in 1 second, then pauses for another second before completing the third process in 1 second This test case was added on 2025-03-23.
Example 3
Input:
processSize = [2, 5, 8]
capacity = [6, 7, 4]
Output:
-1
Explanation: No processor has the required capacity to process the third process (size = 8), so there is no way to process them all. This test case was added on 2025-03-23.