Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- //your code here
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- int a[]=new int[n];
- for(int i=0;i<n;i++)
- {
- a[i]=sc.nextInt();
- }
- int b=sc.nextInt();
- int c,ind=0,ind1=0,ind2=0,ind3=0,ind4=0,count,count1=Integer.MIN_VALUE;
- int u=0;
- for(int i=0;i<n;i++)
- {
- if(a[i]==0)
- {
- c=0;
- for(int j=i;j<n;j++)
- {
- if(c==b)
- break;
- if(a[j]==0)
- {
- u++;
- c++;
- ind1=j;
- }
- }
- if(c<=b)
- {
- ind=i-1;
- ind2=ind1+1;
- ind3=i;
- ind4=ind1;
- while(ind>=0)
- {
- if(a[ind]==0)
- break;
- else
- ind3=ind;
- ind--;
- }
- while(ind2<=(n-1))
- {
- if(a[ind2]==0)
- break;
- else
- ind4=ind2;
- ind2++;
- }
- count=ind4-ind3+1;
- if(count>count1)
- {
- count1=count;
- }
- }
- }
- }
- if(u>0)
- System.out.println(count1);
- else System.out.println(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement