Get Process Time
There is a dual core processor with one process queue for each core. There are n processes, where the time to process the ith process is denoted by time[i] (1 ≤ i ≤ n). There is a latch that helps decide which process is processed by which core. Initially, the first core has the latch. Suppose the latch is currently with the cth core, where c is either 1 or 2, and the ith process needs to be assigned. Then one of the following operations must be performed:
i+1th process assigned to the core c and the latch is given to the other core.i+1th process is assigned to the other core, and the latch is retained by the core c.
The aim of each core is to have a maximum sum of time of processes with them for better performance. So, while assigning the ith process, the core with the latch decides the operation to be performed such that the total sum of time of processes assigned to it is maximized after all the processes are assigned.
Find the sum of the time of processes assigned to the first and second cores if both the cores work optimally. Return an array of two integers, where the first integer is the sum of the time of processes assigned to the first core, and the second integer is the aim of the time of processes assigned to the second core.
Complete the function getProcessTime in the editor below.
getProcessTime has the following parameter:
int time[n]: the processing time required for each process
Returns
long[2]: the sums of processing times of the first and second cores
1Example 1

Let's have an example, initially, the first core has the latch and the total time of processes for the first core is (10 + 21) = 31, and the total time of processes for the second core is (10 + 10 + 20). The given assignment is not optimal, the optimal time for the processes for the first core is (21+10+21)=52, and the total time of processes for the second core is (10 + 10) = 20. The given assignment is not optimal total as for the 4th process, the 2nd core assigned the process with process time = 21 to core 1 and got the 5th process with process time = 10, which is not an optimal move by core 2. The optimal move by the 2nd core would have been to assign the 4th process to itself and the 5th process to core, this would have given the total process time to the 2nd core = 31, which is better than 20.
An optimal assignment is shown.
Hence, the total time of processes for the first core is (10 + 21 + 10) = 41, and the total time of processes for the second core is (10 + 21) = 31.
Return the answer array, [41, 31].
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 10^51 ≤ time[i] ≤ 10^9