zoukankan      html  css  js  c++  java
  • Codeforces Round #520 (Div. 2) A. A Prank

    JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a1a1, a2a2, ..., anan of integers, such that 1≤a1<a2<…<an≤1031≤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][1,103].

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

    Input

    The first line of the input contains a single integer nn (1≤n≤1001≤n≤100) — the number of elements in the array.

    The second line of the input contains nn integers aiai (1≤a1<a2<⋯<an≤1031≤a1<a2<⋯<an≤103) — the array written by Giraffe.

    Output

    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 00.

    Examples

    input

    Copy

    6
    1 3 4 5 6 9
    

    output

    Copy

    2

    input

    Copy

    3
    998 999 1000
    

    output

    Copy

    2

    input

    Copy

    5
    1 2 3 4 5
    

    output

    Copy

    4

    Note

    In the first example, JATC can erase the third and fourth elements, leaving the array [1,3,_,_,6,9][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,_,_][998,_,_]. Because all the elements are less than or equal to 10001000, the array is still can be restored. Note, that he can't erase the first 22 elements.

    In the third example, JATC can erase the first 44 elements. Since all the elements are greater than or equal to 11, Giraffe can still restore the array. Note, that he can't erase the last 44 elements.

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int a[1000+10];
        int b[1000+10];
        int n,m,j,k,i,T;
        while (cin>>n)
        {
            j=0;
            for (i=0;i<n;i++)
            {
                cin>>a[i];
            }
            int sum=1;
            for (i=1;i<=n-1;i++)
            {
                if (a[i]==a[i-1]+1   )
                {
                    sum++;
                }
                else
                {
                    b[j++] = sum++;
                    sum=1;
                }
            }
            b[j++] = sum;
            int ans  = *max_element(b,b+j);
            if (ans==1)
            cout<<"0"<<endl;
            else if (ans==b[0] && a[0]==1)
                cout<<ans-1<<endl;
            else if (ans==b[j-1] && a[n-1]==1000)
                cout<<ans-1<<endl;
            
            else
                cout<<ans-2<<endl;
    
    
            /*for (i=0;i<j;i++)
            cout<<b[i]<<" ";
            cout<<endl;*/
        }
    
        return 0;
    }
  • 相关阅读:
    [原]如何在Android用FFmpeg+SDL2.0之同步视频
    鹤山市五泉酒厂 (“侨乡情”酒 )
    买酒的网站(转)
    泥鳅、黄鳝有关技术。
    国产 冰葡萄酒 主要生产地、品牌
    对症治疗过敏性鼻炎,依巴斯汀比氯雷他定更有效
    魔筎精粉制作 ----新化联系人
    拉肚子使用的常见药物
    一些WCF DS 的资料(参考)
    SHAREPOINT 2013 + PROJECT 2013 资料网站
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451266.html
Copyright © 2011-2022 走看看