No test case passed

#include<bits/stdc++.h>
using namespace std;

bool compare(pair<int,int>p1,pair<int,int>p2){
if(p1.second!=p2.second){
return p1.second<p2.second;
}else{
return p1.first<p2.first;
}
}

int ans(vector<pair<int,int>>v){
sort(v.begin(),v.end(),compare);
int res = 1;
int fin = v[0].second;
for(int i=1;i<v.size();i++){
if(v[i].first>=fin){
res++;
fin = v[i].second;
}
}

return res;

}

int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
vector<pair<int,int>>v;
for(int i=0;i<n;i++){
int x;
int y;
cin>>x;
cin>>y;
v.push_back(make_pair(x,y));
cout << ans(v) << endl;

}

}

}

what is wrong with this code

Write this statement after for loop.

Hope it helps.

@Mohitpandey29
Please mark your doubt as resolved.

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.