Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5 + 7;
- const int INF = 1e9 + 7;
- int ar[N];
- int main()
- {
- int n; cin >> n;
- vector<int> f(n + 7, INF);
- f[0] = -INF;
- for(int i = 0 ; i < n ; i ++)
- cin >> ar[i];
- for (int i = 0 ; i < n ; i ++)
- {
- int j = (upper_bound(f.begin(), f.end(), ar[i]) - f.begin());
- if (f[j-1] < ar[i] && ar[i] < f[j])
- f[j] = ar[i];
- }
- int l = -1, r = -1;
- for(int i = 1 ; i <= n ; i ++)
- {
- if(f[i] != INF && f[i] != -INF)
- {
- r = i;
- if(l == -1)
- l = i;
- }
- }
- cout << r - l + 1 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement