Advertisement
askarulytarlan

Untitled

Feb 5th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. struct Pair {
  7. int l, r;
  8. } a[100500];
  9.  
  10. bool cmp(Pair p1, Pair p2) {
  11. return p1.r < p2.r;
  12. }
  13.  
  14. int main() {
  15. int n;
  16. cin >> n;
  17.  
  18. for (int i = 1; i <= n; i++)
  19. cin >> a[i].l >> a[i].r;
  20.  
  21. sort(a + 1, a + n + 1, cmp);
  22.  
  23. int last = 0, ans = 0;
  24.  
  25. for (int i = 1; i <= n; i++) {
  26. if (a[i].l > last)
  27. ans++, last = a[i].r;
  28. }
  29.  
  30. cout << ans;
  31.  
  32. return 0;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement