Reg:- clearity in question

Is it compusory to take 0th time slot ? or any slot can be taken to maximize the count of activity ?

hello @somilgupta4
you should take that activity whose ending time is smallest.
and because we have already sorted the activities on the basis of ending time.
0th index activity will always have smallest ending time.
therefore we will always choose 0th activity as our very first activity.

strong text#include<bits/stdc++.h>
using namespace std;
bool comparator (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;
vector<pair<int,int>> v(n);
int f=0;
for (int i=0;i<n;i++)
{
cin>>f;
cin>>s;

	v[i].first=f;
	v[i].second=s;
}
int count=1;

sort(v.begin(),v.end(),comparator);

s=v[0].second;
for (int i=1;i<n;i++)
{
	if(v[i].first>=s)
	{
		count++;
		s=v[i].second;
	}
}

cout<<count<<endl;
count=1;


}
return 0;

}

Can you tell me plz why this code isn’t working ?