Naxocist

Orchid

May 4th, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using pi = pair<int, int>;
  6. using tiii = tuple<int, int, int>;
  7. const int N = 1e6 + 3;
  8. vector<int> lis;
  9.  
  10. int main() {
  11.     // freopen("input.in", "r", stdin);
  12.     int n; scanf("%d", &n);
  13.     int mx = -1e9;
  14.     for(int i = 0; i < n; ++i) {
  15.         int x; scanf("%d", &x);
  16.  
  17.         auto it = upper_bound(lis.begin(), lis.end(), x);
  18.  
  19.         if(it == lis.end()) lis.push_back(x);
  20.         else *it = x;
  21.     }
  22.  
  23.     printf("%d", n - lis.size());
  24.    
  25.     return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment