# Codeforces Round #520 (Div. 2) A. A Prank

A. A Prank

time limit per test   1 second
memory limit per test    256 megabytes

Description:

JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range

JATC wonders what is the greatest number of elements he can erase?

Input:

The first line of the input contains a single integer

The second line of the input contains

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

const int N = 1005;
int a[N],d[N];
int n,ans=0;

int main(){
scanf("%d",&n);
a[n+1]=1001;
for(int i=1;i<=n;i++) scanf("%d",&a[i]) , d[i]=a[i]-a[i-1];
d[n+1]=a[n+1]-a[n];
int cnt = 0;
for(int i=2;i<=n+1;i++){
if(d[i]==d[i-1] &&d[i]==1){
cnt++;
}else{
ans=max(ans,cnt);
cnt=0;
}
}
printf("%d",max(ans,cnt));
return 0;
}

posted @ 2018-11-19 22:34  heyuhhh  阅读(269)  评论(0编辑  收藏  举报