diff --git a/C++/Job_sequencing_problem.cpp b/C++/Job_sequencing_problem.cpp new file mode 100644 index 00000000..3142026f --- /dev/null +++ b/C++/Job_sequencing_problem.cpp @@ -0,0 +1,89 @@ +#include +using namespace std; + +struct Job +{ + int id; + int dead; + int profit; +}; + + +class Solution +{ + public: + static bool comp(Job& j1, Job& j2) + { + return j1.profit > j2.profit; + } + vector JobScheduling(Job arr[], int n) + { + // your code here + sort( arr,arr+n,comp); + // To know the max deadline + int max_deadline=arr[0].dead; + for( int i=0;i0;j--) + { + if( job_slot[j]==-1) + { + job_slot[j]=i; + profit=profit+arr[i].profit; + job_count++; + break; + } + } + } + + vectorresult; + result.push_back(job_count); + result.push_back(profit); + + return result; + } +}; + +int main() +{ + int t; + + cin >> t; + + while(t--){ + int n; + + + cin >> n; + Job arr[n]; + + + for(int i = 0;i> x >> y >> z; + arr[i].id = x; + arr[i].dead = y; + arr[i].profit = z; + } + Solution ob; + + vector ans = ob.JobScheduling(arr, n); + cout<