fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. bool sort_sec(pair<int,int> a,pair<int,int> b)
  6. {
  7. return a.second<b.second;
  8. }
  9.  
  10. int main() {
  11. int m;
  12. cin>>m;
  13. while(m>0)
  14. {
  15. int n,c=1;
  16. cin>>n;
  17. pair<int,int> p[n];
  18. for(int i=0;i<n;i++)
  19. cin>>p[i].first>>p[i].second;
  20. sort(p,p+n,sort_sec);
  21. int j=0;
  22. for(int i=1;i<n;i++)
  23. {
  24. if(p[i].first >= p[j].second){
  25. j=i;
  26. c++;
  27. }
  28. }
  29. cout<<c<<endl;
  30. m--;
  31. }
  32. return 0;
  33. }
  34.  
  35. // output:
  36. // 1
  37. // 2
  38. // 3
Success #stdin #stdout 0s 4400KB
stdin
3
3
3 9
2 8
6 9
4
1 7
5 8
7 8
1 8
6
7 9
0 10
4 5
8 9
4 10
5 7
stdout
1
2
3