fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7. vector<int>v(n);
  8. for(int i=0;i<n;i++) cin>>v[i];
  9. vector<int>temp;
  10. temp.push_back(v[0]);
  11. for(int i=1;i<n;i++)
  12. {
  13. if(v[i]>=temp[temp.size()-1])
  14. temp.push_back(v[i]);
  15. else
  16. {
  17. int t=upper_bound(temp.begin(),temp.end(),v[i])-temp.begin();
  18. temp[t]=v[i];
  19. }
  20. }
  21. // for(auto i:temp) cout<<i<<" ";
  22. cout<<temp.size();
  23. return 0;
  24. }
Success #stdin #stdout 0s 4264KB
stdin
6
2 1 4 3 6 5
stdout
3