What i am doing wrong plz check

test case is not passing

#include<bits/stdc++.h> using namespace std; bool compare(pair<int,int> a, pair<int,int> b){ return a.second<b.second; } int main() { int t; cin>>t; while(t–){ int n; cin>>n; pair<int,int> arr[n]; for(int i=0; i<n; i++){ cin>>arr[i].first; cin>>arr[i].second; } sort(arr,arr+n,compare); int sec[n]; for(int i=0; i<n; i++){ sec[i]=arr[i].first; } //cout<<arr[3].second<<endl; int count=0,i; for(i=0; i<n;){ // cout<<arr[i].first<<" "; // cout<<arr[i].second; //cout<<endl; count++; auto it=lower_bound(sec,sec+n,arr[i].second); i=it-sec; } cout<<count<<endl; } return 0; }

Share your code using ide.codingblocks.com by pasting your code there, press cntr+s, a special url will be generated. Share that url with me

plz check this https://ide.codingblocks.com/s/410387 can you tell why lower_bound(14) giving directly 37 not 32 plz do check it

sec array has all those elements in sorted ascending orders of ending time of each activity.


So you are calculating lower bound on sec that is s which is not even sorted.(line number 32 of your code)
So when you check lower bound on sec for value 14 it will give you false value only as lowerbound works on sorted array. That’s why i told you to change you approach as activity selection problem is a classy greedy problem. So it has a fixed way to get solved. I have given you implementation, theory , video lectures as well as code. Now proceed accordingly.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.