Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n,d[100],p[100],j[1000],s[1000];
- class JobSequence{
- public:
- void input()
- {
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>p[i]>>d[i];
- s[i]=i;
- }
- }
- int find_sequence()
- {
- selection_sort();
- d[0] = j[0] = 0;
- j[1] = 1;
- int k = 1;
- for(int i =2; i<=n; i++)
- {
- int r = k;
- while(d[i] < d[j[r]] && d[j[r]] != r)
- {
- r = r-1;
- }
- if(d[i] >= d[j[r]] && d[i] > r)
- {
- for(int q=k; q>=r+1; q--)
- j[q+1] = j[q];
- j[r+1] = i;
- k = k+1;
- }
- }
- return k;
- }
- void selection_sort()
- {
- for(int i =1;i<=n;i++)
- {
- int max_index = i;
- for(int j =i+1;j<=n;j++)
- {
- if(p[j]>p[max_index])
- max_index = j;
- }
- swap(p[i],p[max_index]);
- swap(d[i],d[max_index]);
- swap(s[i],s[max_index]);
- }
- }
- };
- int main()
- {
- freopen("input.txt","r",stdin);
- JobSequence js;
- js.input();
- int total_job=js.find_sequence();
- for(int i =1;i<=n;i++)
- cout<<p[i]<<" "<<d[i]<<" "<<s[i]<<endl;
- cout<<"Total selected job = "<<total_job<<endl;
- cout<<endl<<"Sequence of selected job = ";
- for(int i =1;i<=total_job;i++)
- {
- cout<<j[i]<<" ";
- }
- }
- /*
- input
- 5
- 15 3
- 10 1
- 5 2
- 1 2
- 20 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement