fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6. int main() {
  7. cin >> n;
  8. int maxCount = -1;
  9. int count = 0;
  10. vector<pair<int, int>> a(n + 1);
  11. for (int i = 1; i <= n; i++) {
  12. cin >> a[i].first >> a[i].second;
  13. }
  14. bool visited[n + 1] = {false};
  15. int prev_end = -1;
  16. sort(a.begin(), a.end(), [](pair<int, int> a, pair<int, int> b) {
  17. return a.second < b.second;
  18. });
  19. for(int i = 1; i <= n; i++) {
  20. if (a[i].first > prev_end) {
  21. prev_end = a[i].second;
  22. count++;
  23. }
  24. }
  25. cout << count;
  26. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty