Advertisement
askarulytarlan

Untitled

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