-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobsequencing.cpp
More file actions
32 lines (31 loc) · 842 Bytes
/
Jobsequencing.cpp
File metadata and controls
32 lines (31 loc) · 842 Bytes
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
class Solution
{
public:
static bool cmp(Job& J1,Job& J2)
{
return J1.profit>J2.profit;
}
vector<int> JobScheduling(Job arr[], int n)
{
asis of Profit in descending order
sort(arr,arr+n,cmp);
bool Deadline[100001]={0};
int count=0,profit=0;
for(int i=0;i<n;i++)
{
int currdead=arr[i].dead;
int currprofit=arr[i].profit;
while(currdead>=1 && Deadline[currdead]==1)
{
currdead--;
}
if(currdead>=1)
{
Deadline[currdead]=1;
profit+=currprofit;
count++;
}
}
return {count,profit};
}
};