fork(34) download
  1. #include <iterator>
  2. #include <cstdio>
  3. #include <set>
  4. using namespace std;
  5. int main()
  6. {
  7. int n;
  8. scanf ("%d", &n);
  9. int a[n];
  10. for (int i = 0; i < n; ++i)
  11. scanf ("%d", &a[i]);
  12. set<int> st;
  13. set<int>::iterator it;
  14. st.clear();
  15. for (int i = 0; i < n; ++i)
  16. {
  17. st.insert(a[i]);
  18. it = st.find(a[i]);
  19. ++it;
  20. if (it != st.end())
  21. st.erase(a[i]);
  22. }
  23. printf ("%d\n",st.size());
  24. return 0;
  25. }
Success #stdin #stdout 0s 3432KB
stdin
5
1 4 2 4 3
stdout
2