i don’t know why my code doesn’t pass all the test cases
Test_case not satisfied
here is the code which i have written.
#include #include using namespace std; bool compare(pair<int,int>s1, pair<int,int>s2){ int i1,i2; i1=s1.first; i2=s2.first; return i1==i2; } int func_1(int n,pair<int , int>s1[]){ int max=1; for(int i=0;i<n;i++){ int k=i; int count=1; for(int j=k;j<n;j++){ if(s1[k].second<=s1[j].first){ count++; k=j; } } if(max<count) max=count; } return max; } int main() { int T; cin>>T; for(int i=0;i<T;i++){ int n; cin>>n; pair<int,int>activity[n]; for(int j=0;j<n;j++){ cin>>activity[j].first>>activity[j].second; } //sort(activity,activity+n,compare); cout<<func_1(n,activity)<<"\n"; /for(int i=0;i<n;i++){ cout<<activity[i].first<<" “<<activity[i].second<<”\n"; }/ } return 0; }
sorry for bad msg , i have sent it in your chat box
There was a problem in your comparator function. You just need to sort pairs on basis of their finish time.
Corrected Code: https://ide.codingblocks.com/s/192550
Hope it Helps.
yes , your code is working fine , i have understand the concept but please let me know that my logic of understanding is correct or not. can you please tell me why we do sorting according to finish time and not starting time.