


If a particular job has a deadline 'x', it means that it needs to be completed at any time before 'x'.
Assume that the start time is 0.
'N' = 3, Jobs = [[1, 1, 30], [2, 3, 40], [3, 2, 10]].
All the jobs have different deadlines. So we can complete all the jobs.
At time 0-1, Job 1 will complete.
At time 1-2, Job 3 will complete.
At time 2-3, Job 2 will complete.
So our answer is [3 80].
The first line contains a single integer 'N', denoting the number of elements of the array 'Jobs'.
Next 'N' lines contain three integers, id, deadline, and profit of the 'ith' job.
The only line contains the number of jobs to be done to get maximum profit and maximum profit.
You do not need to print anything. It has already been taken care of. Just implement the given function.
The idea here is to follow a greedy approach that we should complete the job with the maximum profit in the nearest available slot within its deadline. So, we can sort the jobs in the decreasing order of their profit, and we can maintain a boolean array to keep track of the available slots. So, for each job, we traverse the array backward from the deadline associated with the job to 1, and if any of the slots are empty, we add this profit to the answer and increase our count, else we ignore this job.
Algorithm
In the above approach, for each index in the jobs array, we may have to traverse a boolean array of slots of size maxDeadline. However, we can optimize the above approach by using a set and applying a binary search on the elements of the set. So, we store the elements from maxDeadline to 1 in the set. We traverse the jobs array, and for each job, we find the nearest element present in the set that is less than or equal to the deadline of that job. If such an element exists in the set, we add the profit to the answer, increase our count, and remove this element from the set.
Algorithm
Note that, there is no in-built lower_bound or upper_bound function associated with the set data structure in python. So, we can implement the above approach in python by using a segment tree.