1 solutions

  • 0
    @ 2025-12-2 15:45:01

    C++ :

    #include<bits/stdc++.h> 
    using namespace std;
    int n,k,a[100005],b[100005];
    int main()
    {
        cin>>n>>k;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0)b[i]=b[i-1]+1;
            else b[i]=b[i-1];
        }
        int c=0;
        int max=-1000000;
        for(int i=1;i<=n;)
        {
            if(b[i]-b[c]<=k)
            {
                if(i-c>max)
                    max=i-c;
                i++;
            }
            else
                c++;
        }
        cout<<max;
        return 0;
    }
    
    • 1

    Information

    ID
    668
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    2
    Uploaded By