fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false), cin.tie(nullptr);
  6. int n; cin >> n;
  7. vector <pair <int, int>> v(n);
  8. for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
  9. sort(v.begin(), v.end());
  10. int ans = 0, lim = 0;
  11. for (int i = 0; i < n; ++i) {
  12. if (v[i].second < lim) ++ans;
  13. else lim = v[i].second;
  14. }
  15. cout << ans << endl;
  16. }
  17.  
Success #stdin #stdout 0.01s 5316KB
stdin
5
3 5 2 1 4
4 3 2 5 1
stdout
2