Advertisement
unknown_0711

Untitled

Jul 25th, 2022
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main
  6. {
  7.     public static void main (String[] args) throws java.lang.Exception
  8.     {
  9.         //your code here
  10.       Scanner sc=new Scanner(System.in);
  11.       int n=sc.nextInt();
  12.       int a[]=new int[n];
  13.       for(int i=0;i<n;i++)
  14.         {
  15.           a[i]=sc.nextInt();
  16.         }
  17.       int b=sc.nextInt();
  18.       int c,ind=0,ind1=0,ind2=0,ind3=0,ind4=0,count,count1=Integer.MIN_VALUE;
  19.       int u=0;
  20.       for(int i=0;i<n;i++)
  21.         {
  22.           if(a[i]==0)
  23.           {
  24.             c=0;
  25.             for(int j=i;j<n;j++)
  26.               {
  27.                 if(c==b)
  28.                 break;
  29.                 if(a[j]==0)
  30.                 {
  31.                   u++;
  32.                   c++;
  33.                   ind1=j;
  34.                 }
  35.               }
  36.               if(c<=b)
  37.               {
  38.                 ind=i-1;
  39.                 ind2=ind1+1;
  40.                 ind3=i;
  41.                 ind4=ind1;
  42.                 while(ind>=0)
  43.                 {
  44.                  if(a[ind]==0)
  45.                   break;
  46.                  else
  47.                   ind3=ind;
  48.                  ind--;
  49.                 }
  50.                 while(ind2<=(n-1))
  51.                {
  52.                  if(a[ind2]==0)
  53.                    break;
  54.                  else
  55.                   ind4=ind2;
  56.                 ind2++;
  57.                }
  58.               count=ind4-ind3+1;
  59.               if(count>count1)
  60.               {
  61.                count1=count;
  62.               }
  63.              }
  64.         }
  65.         }
  66.       if(u>0)
  67.       System.out.println(count1);
  68.       else System.out.println(n);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement