Advertisement
Guest User

Untitled

a guest
Dec 8th, 2014
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2. #include<utility>
  3. #include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int total=1;
  8. int N,i,j;
  9. cin >> N;
  10. pair<long int,long int> pi[N];
  11. for(i=0;i<N;i++)
  12. {
  13. cin >> pi[i].first >> pi[i].second;
  14. }
  15. sort(pi,pi+N);
  16. int x=0;
  17. int y=1;
  18. while(x<N-1)
  19. {
  20. while(y<N)
  21. {
  22. if(pi[x].second<pi[y].first)
  23. {
  24.  
  25. x=y;
  26. y=y+1;
  27. total=total+1;
  28. }
  29. else if (pi[x].second>=pi[y].first && pi[x].second>pi[y].second)
  30. {
  31.  
  32. x=y;
  33. y=y+1;
  34. }
  35. else
  36. y=y+1;
  37. }
  38. x=x+1;
  39. }
  40. cout<<total<<"\n";
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement