Activity Selection Problem

// this is my code please tell me the problem

#include
using namespace std;
int main() {
int t,n,i,j,k=1;
int arr[1000][1000];
cin>>t;
while(t>0)
{ k=1;
cin>>n;
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
cin>>arr[i][j];
}
int m=1;
for(i=0;i<n&&m<n;)
{
if(arr[i][1]<=arr[m][0])
{
k++;
i=m;
m++;
}
else
{
m++;
}
}
t–;
cout<<k<<endl;
}

return 0;

}

hello @lovish2552
u need to sort the actvities on basis of ending time and then apply logic.

But during dry run my output is correct and this logic is also correct i think so…please tell whats wrong in this code

please save ur code here


and share link with me

this is the code link

run ur code for this test case
1
3
2 6
3 5
1 3

output should be 2 ( 1, 3 and 3,5 ) but urs is giving 1.

so can you tell me how can i sort this 2d array please give me code only to sort this

store acitvity in pairs and then write ur own comparator to sort the activities and then apply ur logic.
pls refer this -> https://ide.codingblocks.com/s/246953

Ok thank you So much