forked from striver79/SDESheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobSequencingCpp
39 lines (32 loc) · 848 Bytes
/
jobSequencingCpp
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
// Prints minimum number of platforms reqquired
// This function is used for sorting all jobs according to profit
bool comparison(Job a, Job b)
{
return (a.profit > b.profit);
}
pair<int,int> JobScheduling(Job arr[], int n)
{
sort(arr, arr + n, comparison);
int maxi = arr[0].dead;
for(int i = 1;i<n;i++) {
maxi = max(maxi, arr[i].dead);
}
int slot[maxi + 1];
for (int i=0; i<=maxi; i++)
slot[i] = -1;
int countJobs = 0, jobProfit = 0;
for (int i=0; i<n; i++)
{
for (int j=arr[i].dead; j>0; j--)
{
if (slot[j]==-1)
{
slot[j] = i;
countJobs++;
jobProfit+=arr[i].profit;
break;
}
}
}
return make_pair(countJobs, jobProfit);
}