Company: Rippling
Difficulty: medium
Minimum Time to Execute Processes There are n processes. The size of process i is processSize[i] , for 0 <= i < n . There are also m processors; processor j has capacity capacity[j] , for 0 <= j < m . A processor can execute a process in 1 second when the process size is at most its capacity. It cannot execute a larger process. A processor may execute several processes one after another, but after every completed process except its last assigned process it must pause for 1 second before starting the next one. Different processors can work simultaneously. Determine the minimum number of seconds needed to execute all processes. Return -1 if at least one process cannot be assigned to any processor. Input Format The input is four whitespace-separated lines: The first line contains n . The second line contains the n values of processSize . The third line contains m . The fourth line contains the m values of capacity . Output Format Print one integer: the minimum completion time,