每次可以把一辆车放在开头或者结尾
问最少多少次操作让这个数列变成递增数列
既然要保持最少操作,那就需要让最长的上升序列的数保持不变,让其他数进行改变
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 100000 + 10;
int a[maxn], b[maxn];
int main(){
int n;
scanf("%d", &n);
int tot = 1;
int ans = 1;/// ans != 0 if n = 1 then GG
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
b[a[i]] = i;
}
for(int i = 2; i <= n; i++){
if(b[i] > b[i-1]) ++tot;
else tot = 1;
ans = max(ans, tot);
}
printf("%d\n", n - ans);
return 0;
}