#include #define REP(i, n) for (int i = 0; (i) < int(n); ++ (i)) using namespace std; int main() { // input int n; cin >> n; vector a(n); REP (i, n) cin >> a[i]; // solve REP (i, n) a[i] -= 1; multiset dp; int shift = 0; for (int a_i : a) { auto it = dp.lower_bound(a_i); if (it != dp.end()) { dp.erase(it); ++ shift; } dp.insert(a_i); } // output cout << shift << endl; return 0; }