a[i]=a[i]-i
则不难发现 对a[i]中>=0的元素 求一遍单增子序列(非严格)
答案就=n-lis
#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const int N = 1e5 +5 ;
int b[N];
int lcs(int*a,int n){
int m=0;
for(int i=0;i<n;++i){
if(a[i]<0){
continue;
}
if(!m||a[i]>=a[m-1]){
a[m++]=a[i];
continue;
}
int*it=upper_bound(a,a+m,a[i]);
if(it==a+m){
a[m++]=a[i];
}
else{
*it=a[i];
}
}
return m;
}
int main(){
int n;
while(~scanf("%d",&n)){
int m=0;
for(int i=0;i<n;++i){
scanf("%d",&b[i]);
b[i]-=(i+1);
}
printf("%d\n",n-lcs(b,n));
}
return 0;
}