fork download
  1. #pragma GCC optimize("Ofast")
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define y0 holdtheflower
  7. #define y1 enjoythecolorandscent
  8. #define yn walkthroughthesoulgarden
  9. #define j1 feelthewarmbreathofkindnessandsalvation
  10.  
  11. #define endl '\n'
  12. mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
  13. mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
  14.  
  15. int n;
  16. vector<pair<int, int>> a;
  17.  
  18. void Input() {
  19. cin >> n; a.resize(n);
  20. for (auto &P: a) cin >> P.second >> P.first;
  21. }
  22.  
  23. void Solve() {
  24. sort(a.begin(), a.end());
  25. int ans = 1, last = a[0].first;
  26. for (int i=1; i<n; i++) {
  27. if (a[i].second >= last) {
  28. ans++;
  29. last = a[i].first;
  30. }
  31. }
  32. cout << ans << endl;
  33. }
  34.  
  35. int main(int argc, char* argv[]) {
  36. ios_base::sync_with_stdio(0); cin.tie(NULL);
  37. Input(); Solve(); return 0;
  38. }
  39.  
  40. /******************************************\
  41.  * Thuy-Trang Tran, #Team4T's Leader *
  42.  * #Team4T Primary Flagship - Salvation *
  43. \******************************************/
Success #stdin #stdout 0s 15248KB
stdin
5
7 9
2 4
1 3
1 6
3 7
stdout
3