#include #include #include #include using namespace std; int ans, n, l, r, c; int a[200000], d[200000]; /* For solving this problem u have to search longest decreasing subsequence, using O(N log N) algorithm. */ int main(){ ios::sync_with_stdio(false); //Read input cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; //Standart algorithm d[0] = 1000000000; for (int i = 0; i < n; ++i) { l = 0; r = i+1; while (l + 1 < r) { c = (l + r) / 2; if (a[i] < d[c]) l = c; else r = c; } d[l + 1] = max(d[l + 1], a[i]); // Try to modify answer ans = max(ans, l + 1); } cout << ans << endl; return 0; }