fork download
  1. #include<bits/stdc++.h>
  2. #define ull unsigned long long
  3. #define ll long long
  4. #define all(x) x.begin(), x.end()
  5. using namespace std;
  6. const int maxn = 1e6 + 5;
  7. int A[maxn];
  8. int main() {
  9. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  10. int n, thetich, dem = 0;
  11. cin >> n;
  12. for (int i = 1; i <= n; ++i) {
  13. cin >> thetich;
  14. int it = lower_bound(A + 1, A + dem + 1, thetich) - A;
  15. if (it > dem) {
  16. dem++;
  17. A[dem] = thetich;
  18. }
  19. else{
  20. A[it] = thetich;
  21. }
  22. }
  23. cout << dem;
  24. }
  25.  
  26.  
Success #stdin #stdout 0s 5280KB
stdin
5
4 5 3 2 6
stdout
3