Give you a array from small to large with array numbers within [1,1000]. Now you want to delete one of the numbers, but you still want to ensure that you can restore this string of numbers. What is the maximum length you can delete?
Add a 0 on the left and 1001 on the right. The violent enumeration range can be.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
int n, a[MAXN];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
n++;
a[n] = 1001;
int ans = 0, cnt = 1;
for (int i = 0; i <= n; i++)
{
for (int j = i+1; j <= n; j++)
{
if (a[j]-a[i] == j-i) ans = max(ans, j-i-1);
}
}
printf("%d\n", ans);
return 0;
}
/*
6
1 3 4 5 6 9
*/