每次可以把一輛車放在開頭或者結尾
問最少多少次操作讓這個數列變成遞增數列
既然要保持最少操作,那就需要讓最長的上升序列的數保持不變,讓其他數進行改變
#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;
}