Advertisement
anon20016

K

Nov 22nd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. const int N = 239020;
  13. const int INF = 1000000007;
  14.  
  15. int a[N], d[N];
  16.  
  17. int main() {
  18.  
  19. int n;
  20. cin >> n;
  21. for (int i = 0; i < n; i++) {
  22. cin >> a[i];
  23. }
  24. d[0] = -INF;
  25. for (int i = 1; i <= n; ++i)
  26. d[i] = INF;
  27. int ans = 0;
  28. for (int i = 0; i < n; i++) {
  29. int j = int(upper_bound(d, d + n, a[i]) - d);
  30. if (d[j - 1] < a[i] && a[i] < d[j]) {
  31. d[j] = a[i];
  32. }
  33. }
  34. for (int i = 0; i < n; i++) {
  35. if (d[i] != INF) {
  36. ans = max(ans, i);
  37. }
  38. }
  39. cout << ans;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement