Mustafiz04 / Contribute-to-HacktoberFest2021

A beginner-friendly project to help you in open-source contributions. Made specifically for contributions in HACKTOBERFEST 2021! From Hello World Programs to Data Structure and Algorithms! all in one. Please leave a star ⭐ to support this project! ✨
https://hacktoberfest.digitalocean.com/
MIT License
44 stars 161 forks source link

1st pull request #274

Open fantom787 opened 3 years ago

fantom787 commented 3 years ago

include <bits/stdc++.h>

using namespace std;

void SelectActivities(vectors,vectorf){

vector<pair<int,int>>ans;

priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>p;

for(int i=0;i<s.size();i++){
    p.push(make_pair(f[i],s[i]));
}

auto it = p.top();
int start = it.second;
int end = it.first;
p.pop();
ans.push_back(make_pair(start,end));

while(!p.empty()){
    auto itr = p.top();
    p.pop();
    if(itr.second >= end){
        start = itr.second;
        end = itr.first;
        ans.push_back(make_pair(start,end));
    }
}
cout << "Following Activities should be selected. " << endl << endl;

for(auto itr=ans.begin();itr!=ans.end();itr++){
    cout << "Activity started at: " << (*itr).first << " and ends at " << (*itr).second << endl;
}

}

int main() { vectors = {1, 3, 0, 5, 8, 5}; vectorf = {2, 4, 6, 7, 9, 9}; SelectActivities(s,f);

return 0;

}