C++ > Algorithms
Job Sequencing with Deadlines while Maximizing Profits
Job Sequencing with Deadlines while Maximizing Profits #include
#include
using namespace std; class node{ public: int d,p,t; bool operator < (node n) { if(p
lst; node pt; cout<<"Enter no of entries "; cin>>n; for(i=0;i
>p>>d>>t; pt.d=d; pt.p=p; pt.t=t; lst.push_back(pt); } int maxd=0; lst.sort(); lst.reverse(); cout<<" sorted list "; list
:: iterator itr=lst.begin(); while(itr!=lst.end()){ pt=*itr; if(maxd
=pt.t) min=pt.t; else min=pt.d; if(maxd>=min) profit+=min*pt.p; else profit+=maxd*pt.p; itr++;maxd=maxd-min; } cout<<"profit is : "<
C++ Codes
Algorithms
Beginners
Code Snippets
Graphics
Data Structures
Games
Mathematics
Miscellaneous