
3 tasks and 16 units of total time.
Task = [( 2, 8 ) , ( 4, 5) , ( 5, 1)]
( 2, 8 ) -> task 1 at position 2 in line and takes 8 sec to complete.
( 4, 5) -> task 2 at position 4 in line and takes 5 sec to complete.
( 5, 1) -> task 3 at position 5 in line and takes 1 sec to complete.
Skipping the first task leaves us enough time to complete the other two tasks. Going to the location of the third task and coming back costs 2x5 =10 sec, and performing tasks at locations 4 and 5 cost us 5+1 = 6 sec.
Total time spent will be 10+6=16 sec.
First-line contains 'T,' denoting the number of Test cases.
For each Test case:
The first line contains two integers, 'N' and ‘totalTime’, where ‘N’ is the number of tasks and ‘totalTime’ is the time given.
Next, the ‘N’ lines contain two integers, ‘Task[i][0]’ and ‘Task[i][1]’, each denoting the distance of the task and the time required to complete the task.
After operating, you must return the maximum number of tasks you can finish in time ‘totalTime’.
You don’t need to print anything. Just implement the given function.
1<= T <=10
1<= N <=10^5
1<= totalTime <=10^9
1<= Task[i][0] <= 10^9
1<= Task[i][1] <= 10^5
Time Limit: 1 sec
For every recursive call-
recur (curTask+1, n,completedTasks+1,task,remTime-task[curtask][1], max( maxDist, task[curTask][0]), answer)
recur (curTask+1, n,completedTasks,task,remTime,maxDist, answer)
Return ‘answer’
totalTime = totalTime - ( 2 * Task[i][0] ) - Task[i][1].
We will do this for all tasks, and the answer to the problem will be the maximum task we can perform among them.
Sort the array of tasks.
Initialize an empty minimum priority_queue that will contain all the tasks we are performing currently.
For the ‘ith’ task in tasks :
totalTime = totalTime - ( 2 * Task[i][0] ) - Task[i][1].