fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5. #define pb push_back
  6. #define ll long long
  7. const int MAXN = 1e4 + 7;
  8. ll n;
  9. pair <ll, ll> a[MAXN];
  10. vector <ll> f;
  11.  
  12. void solve(){
  13. cin >> n;
  14. for(int i = 1; i <= n; i++){
  15. cin >> a[i].fi >> a[i].se;
  16. if(a[i].fi > a[i].se) swap(a[i].fi, a[i].se);
  17. }
  18. sort(a + 1, a + 1 + n, [&](pair<ll,ll> x, pair<ll,ll> y) {
  19. return x.se < y.se;
  20. });
  21.  
  22. for(int i = 1; i <= n; i++){
  23. auto it = lower_bound(f.begin(), f.end(), a[i].fi);
  24. if(it == f.end()) f.pb(a[i].fi);
  25. else *it = a[i].fi;
  26. }
  27. cout << f.size();
  28. }
  29.  
  30. int main(){
  31. ios_base::sync_with_stdio(0);
  32. cout.tie(0);
  33. cin.tie(0);
  34. // freopen("box.inp", "r", stdin); freopen("box.out", "w", stdout);
  35. solve();
  36. }
  37.  
Success #stdin #stdout 0.01s 5288KB
stdin
3
1 1
1 1
1 1
stdout
1