Guest User

YourCode

a guest
Apr 29th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. class Codechef {
  5.  
  6.     public static void main(String[] args) {
  7.         try {
  8.             Scanner sc = new Scanner(System.in);
  9.             int[] A = new int[100];
  10.  
  11.             int T = sc.nextInt();
  12.  
  13.             int i, j, k;
  14.  
  15.             for (k = 1; k <= T; k++) {
  16.                 int flag = 0;
  17.                 int N = sc.nextInt();
  18.                 for (i = 1; i <= N; i++) {
  19.                     A[i] = sc.nextInt();
  20.                     // System.out.print(a[i]+" ");
  21.                 }
  22.                 outerloop: for (i = 1; i <= N; i++) {
  23.                     if (A[i] == 1) {
  24.                         for (j = i + 1; j <= i + 5; j++) {
  25.                             if (A[j] == 1) {
  26.  
  27.                                 // System.out.println("NO");
  28.                                 flag = 1;
  29.                                 break outerloop;
  30.  
  31.                             }
  32.                         }
  33.                     }
  34.                 }
  35.                 if (flag == 1) {
  36.                     System.out.println("NO");
  37.                 } else {
  38.                     System.out.println("YES");
  39.                 }
  40.             }
  41.         } catch (Exception e) {
  42.             return;
  43.         }
  44.  
  45.     }
  46.  
  47. }
Add Comment
Please, Sign In to add comment