Activity selection problem

Whats wrong with this code?
#include

using namespace std;

void activitySelect(int s[100], int f[100], int N){

int i = 0;


int counter = 1;

for(int j = 1; j<N; j++){
    
    if ((s[j] >= f[i]))
    {
        
        i=j;
		counter++;
    }
    else
    {
        continue;
    }
    cout<<counter;
    
}

}
int main(){

int s[10000], f[10000];
int t;
int N;
int n, m;

cin>>t;

while(t>0){
    cin>>N;
    int M = N;
    for(int k = 0; M>0; M--, k++){
        cin>>s[k];
        cin>>f[k];
    }
    
    activitySelect(s, f, N);
    
    t--;
}




return 0;

}

Hey @arjun.12narang
please share ur code in CB IDE

Hey @arjun.12narang
I checked ur code
You are printing inside loop 1st thing
2nd thing u have to use endl after after every testcase
THird thing ur logic in incomplete
Greedy picking is correct but order of activities may not be sorted
So
You have to Sort the activities in the increasing order of ending times and then do a single traversal and pick up activities greedily, i.e, choose an activity whenever possible.

I rechecked my code and changed what you asked for but how to sort the f[] array so that s[] can be sorted correspondingly…

You have to use array/vector of pairs

pair<int,int> arr[n];
for(int i=0;i<n;i++){
     cin>>arr[i].first>>arr[i].second;
}
sort(arr,arr+n);
//use can access using.first and .second

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.