-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjobSequencing.cpp
More file actions
62 lines (52 loc) · 1.15 KB
/
jobSequencing.cpp
File metadata and controls
62 lines (52 loc) · 1.15 KB
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
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int maxiSlot=-1;
int id[n], d[n],p[n];
for(int i=0; i<n; i++) cin>>id[i];
for(int i=0; i<n; i++)
{
cin>>d[i];
maxiSlot=max(maxiSlot,d[i]);
}
for(int i=0; i<n; i++) cin>>p[i];
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(p[i]<p[j])
{
swap(p[j],p[i]);
swap(d[j],d[i]);
swap(id[j],id[i]);
}
}
}
for(int i=0; i<n; i++) cout<<id[i]<<" ";
cout<<endl;
for(int i=0; i<n; i++) cout<<d[i]<<" ";
cout<<endl;
for(int i=0; i<n; i++) cout<<p[i]<<" ";
cout<<endl;
int slot[maxiSlot];
for(int i=0; i<maxiSlot; i++) slot[i]=false;
int totalProfit=0;
for(int i=0; i<n; i++)
{
for(int j=d[i]; j>0; j--)
{
//free slot found
if(slot[j-1]==false)
{
slot[j-1]=true;
totalProfit+=p[i];
//cout<<p[i]<<" ";
break;
}
}
}
cout<<endl<<totalProfit;
}