fork download
  1. /*
  2. Solution By - Amrutansu Garanaik
  3. Codechef ID - dragonemperor
  4. */
  5.  
  6.  
  7. #include<stdio.h>
  8. #include<algorithm>
  9. #include<vector>
  10. using namespace std;
  11. int main()
  12. {
  13. int test,n,s,e;
  14. scanf("%d",&test);
  15. while(test--)
  16. {
  17. scanf("%d",&n);
  18. vector <pair<int,int> > input(n);
  19. for(int i=0;i<n;i++)
  20. {
  21. scanf("%d%d",&s,&e);
  22. input[i]=make_pair(e,s);
  23. }
  24. sort(input.begin(),input.end());
  25. int result=1,prev_end=input[0].first;
  26. for(int i=1;i<n;i++)
  27. {
  28. if(input[i].second>prev_end)
  29. {
  30. prev_end=input[i].first;
  31. result++;
  32. }
  33. }
  34. printf("%d\n",result);
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 3280KB
stdin
2
2
1 3
3 5
2
1 3
4 5
stdout
1
2