-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path11.08.2024.cpp
38 lines (31 loc) · 919 Bytes
/
11.08.2024.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution
{
public:
static bool comp(Job j1, Job j2){
return j1.dead < j2.dead;
}
//Function to find the maximum profit and the number of jobs done.
vector<int> JobScheduling(Job arr[], int n)
{
// your code here
sort(arr, arr+n, comp);
int curr=0, points=0;
priority_queue<int, vector<int>, greater<int>>pq;
for(int i=0;i<n;i++){
if(arr[i].dead>curr){
points+=arr[i].profit;
pq.push(arr[i].profit);
curr++;
}
else{
if(arr[i].profit > pq.top()){
points-=pq.top();
pq.pop();
points+=arr[i].profit;
pq.push(arr[i].profit);
}
}
}
return {curr, points};
}
};