Activity selection probelm? not able to solve,giving me wrong ans

#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int temp=0;
int c=0;
while(n–)
{
int a,b;
cin>>a>>b;
if(a>=temp)
{
temp=b;
c++;
}
}
cout<<c<<endl;
}
return 0;
}

Hi @firozbhaikardar21,
try to modify ur code.This is a greedy problem. Here, if input={(5,6),(1,2),(3,4)} , ur code will give 1 as output whereas after u sort the input, output comes out to be 3.
Try modifying ur code.
If u still hv any doubts, pls post them here.

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.