You are given the ‘N’ processes with their “burst times”, and the “arrival time” for all processes is ‘0’. You are also given the ‘priority’ of each process.
Your task is to find the “waiting time” and the “turn-around time” of each process using the ‘Priority CPU Scheduling’ algorithm.
Note:
1. The highest priority process will be scheduled first, followed by the next highest priority, and so on.
2. If the two processes have the same priority, then you have to run the process with the lowest number (id) first.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the 'T' test cases follow.
The first line of each test case contains a single positive integer, ‘N’, denoting the number of Processes.
The second line of each test case contains ‘N’ space-separated non-negative integer denoting the ‘burst’ time of each process.
The last line of each test case contains ‘N’ space-separated non-negative integers denoting the ‘priority’ of each process.
Output Format:
For each test case, return an array of arrays, where the 1st array will represent the ‘waiting time, and the 2nd array will denote the ‘turn-around time’ of each process.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^4
1 <= BURST[i],PRIORITY[i] <= 10^4
Time Limit: 1sec
1
5
2 1 3 2 1
3 4 1 2 5
2 1 6 4 0
4 2 9 6 1

1
1
3
1
0
3
We have only one process, so it starts at time 0 and ends at time 3.
Sort according to the priority.
O(N*logN), where ‘N’ is the number of processes.
We are sorting the process according to their ‘priority’, and the sorting takes O(N*logN) time.
O(N), where ‘N’ is the number of processes.
As we are creating an extra array of the size ‘N’ to store the ‘burst time’ and ‘priority’ of each process. Hence, space complexity will be O(N).