please check why is this giving the wrong answer. when it is giving the right answer for the sample cases.
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
for(int i =0;i<n;i++){
int len;
cin>>len;
vector<pair<int,int>> v(len);
for (int f=0; f<len; f++){
int a,b;
cin>>a>>b;
v[f].first=a;
v[f].second=b;
}
sort(v.begin(), v.end());
int count =len;
for(int f=0 ; f<len-1 ; f++){
if(v[f].first<=v[f+1].first && v[f+1].first<=v[f].second){
count--;
}
}
cout<<count<<" ";
}
return 0;
}