Help me in solving RUNCOMPARE problem

My issue

how to solve array out of bounds

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{   Scanner sc = new Scanner(System.in);
	      int t = sc.nextInt();
	      for(int i=0;i<t;i++){
	          int n = sc.nextInt();
	              int p =0;
	              int a[]= new int[50];
	              int b[] = new int[50];
	              for( int k=0;k<n-1;k++)
	              {
	              if(a[k]<2*b[k] || b[k]<2*a[k]){
	                  p+=1;
	             
	              System.out.println(n-p);
	              }
	          }
	          
	      }
		
	}
}

Learning course: Arrays using Java
Problem Link: CodeChef: Practical coding for everyone

@indumittal165
Plzz refer the following solution for better understanding of the implementation.

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int T=sc.nextInt();
		while(T-->0){
		    int N=sc.nextInt();
		    int A[]=new int[N];
		    for (int i=0;i<N ;i++ ){
		        A[i]=sc.nextInt();
		    } 
		    int B[]=new int[N];
		    for (int i=0;i<N ;i++ ){
		        B[i]=sc.nextInt();
		    }
		    int count=0;
		    for (int i=0;i<N ;i++ ){
		        int dalice=A[i]*2;
		        int dbob=B[i]*2;
		        
		        if(B[i]<=dalice && A[i]<=dbob){
		            count++;
		        }
		    }
		    System.out.println(count);
		}
	}
}