CF1062A.A Prank
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a1, a2, ..., an of integers, such that 1≤a1<a2<…<an≤103, and then went to the bathroom.
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 [1,103].
JATC wonders what is the greatest number of elements he can erase?
JATC 和他的朋友长颈鹿(Giraffe)正待在房间里一起解题。长颈鹿在黑板上写下一个整数数组 a1, a2, ..., an,满足 1≤a1<a2<…<an≤103,然后去洗手间了。
JATC 决定捉弄一下朋友,擦除数组中若干个连续的元素。但为了不让玩笑开得太过分,他只会以一种方式擦除——使得长颈鹿仍能仅凭剩余元素的信息将原数组完全复原。由于长颈鹿本人构造了该数组,他自然知道这是一个严格递增的数组,且所有元素均为区间 [1,103] 内的整数。
JATC 想知道:他最多可以擦除多少个元素?
输入格式
The first line of the input contains a single integer n (1≤n≤100) — the number of elements in the array.
The second line of the input contains n integers ai (1≤a1<a2<⋯<an≤103) — the array written by Giraffe.
输入的第一行包含一个整数 n(1≤n≤100)—— 表示数组中元素的个数。
输入的第二行包含 n 个整数 ai(1≤a1<a2<⋯<an≤103)—— 表示长颈鹿所写的数组。
输出格式
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 0.
输出一个整数——JATC 能够擦除的数组中连续元素的最大数量。
如果无法擦除任何一个元素,则输出 0。
输入输出样例
输入#1
6 1 3 4 5 6 9
输出#1
2
输入#2
3 998 999 1000
输出#2
2
输入#3
5 1 2 3 4 5
输出#3
4
说明/提示
In the first example, JATC can erase the third and fourth elements, leaving the array [1,3,_,_,6,9]. As you can see, there is only one way to fill in the blanks.
In the second example, JATC can erase the second and the third elements. The array will become [998,_,_]. Because all the elements are less than or equal to 1000, the array is still can be restored. Note, that he can't erase the first 2 elements.
In the third example, JATC can erase the first 4 elements. Since all the elements are greater than or equal to 1, Giraffe can still restore the array. Note, that he can't erase the last 4 elements.
在第一个例子中,JATC 可以擦除第三和第四个元素,得到数组 [1,3,_,_,6,9]。如你所见,空白处仅有一种填充方式。
在第二个例子中,JATC 可以擦除第二和第三个元素,数组将变为 [998,_,_]。由于所有元素均小于等于 1000,该数组仍可被还原。注意:他不能擦除前两个元素。
在第三个例子中,JATC 可以擦除前四个元素。由于所有元素均大于等于 1,长颈鹿仍可还原该数组。注意:他不能擦除最后四个元素。
输入解题思路,AI测评打分。不知道怎么写?