-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJOB_SEQUENCING.cpp
More file actions
53 lines (46 loc) · 846 Bytes
/
Copy pathJOB_SEQUENCING.cpp
File metadata and controls
53 lines (46 loc) · 846 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
typedef long long let;
class job{
public:
let id, deadline, profit;
void get_data(let x, let y, let z){
id = x;
deadline = y;
profit = z;
}
};
bool comparison(job a, job b){
return (a.profit > b.profit);
}
void print_job_schedule(job arr[], let n){
sort(arr, arr+n, comparison);
let i, j, ans[n];
let slot[n] = {0};
for(i=0;i<n;++i){
for(j=min(n, arr[i].deadline)-1; j>=0; --j){
if(!slot[j]){
ans[j] = i;
slot[j] = 1;
break;
}
}
}
for(i=0;i<n;++i){
if(slot[i]){
cout<<arr[ans[i]].id<<" ";
}
}
}
int main(){
freopen("input.txt", "r", stdin);
job arr[100];
let n; cin>>n;
let i; for(i=0;i<n;++i){
let id, deadline, profit;
cin>>id>>deadline>>profit;
arr[i].get_data(id, deadline, profit);
}
print_job_schedule(arr, n);
return 0;
}