fork download
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int n;
  8. cin>>n;
  9.  
  10. int a[n];
  11. for(int i=0;i<n;i++)
  12. {
  13. cin>>a[i];
  14. }
  15.  
  16. multiset<int> towers;
  17. multiset<int>::iterator it;
  18. for(int i=0;i<n;i++)
  19. {
  20. it = towers.upper_bound(a[i]);
  21. if(it == towers.end())
  22. {
  23. towers.insert(a[i]);
  24. }
  25. else
  26. {
  27. towers.erase(it);
  28. towers.insert(a[i]);
  29. }
  30. }
  31.  
  32.  
  33. cout<<towers.size()<<endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5276KB
stdin
5
3 8 2 1 5
stdout
2