PROBLEM LINK:
Author: Kunal Demla
Editorialist: Kunal Demla
DIFFICULTY:
Easy
PREREQUISITES:
Sorting?
SOLUTIONS:
Setters' Solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool comp(vector<int> &a, vector<int> &b)
{
if (a[0] == b[0])
{
return a[1] > b[1];
}
return a[0] < b[0];
}
void solve()
{
ll n,m,x,y,i,j,k,q;
cin>>n;
vector<vector<int>> v(n,vector<int>(2));
for(i=0;i<n;i++)
cin>>v[i][0]>>v[i][1];
sort(v.begin(), v.end(), comp);
int mtn = INT_MIN;
int ans = 0;
for (int i = v.size() - 1; i >= 0; i--)
{
if (v[i][1] < mtn)
ans++;
mtn = max(mtn, v[i][1]);
}
cout<<ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int t=1;
// cout<<t<<endl;
// ${2:is Single Test case?}cin>>t;
cin>>t;
int n=t;
while(t--)
{
//cout<<"Case #"<<n-t<<": ";
solve();
cout<<"\n";
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}