Help me in solving SPREAD2 problem

My issue

not able to take input through scanner class

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 Codechef1
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		ArrayList<Integer> ar = new ArrayList<Integer>();
		while(t-->0)
		{
		    int n = sc.nextInt();
		    int a[] = new int[n];
		    for(int i=0;i<n;i++)
		    a[i] = sc.nextInt();
		    
		    ar.add(snackDown(a,n));
		}

		sc.close();
		
		for(int tt : ar)
		{
		    System.out.println(tt);
		}
		
	}
	
	public static int snackDown(int a[], int n)
	{
	    // ArrayList<Integer> aa = new ArrayList<Integer>();
	    // aa.add(1);
	    int i, c = 1, sum = 1 + a[0];
	    while(sum<n)
	    {
	        c++;
	        for(i=0;i<=c;i++)
	        sum = sum + a[i];
	    }
	    
	    return c;
	}
}

Problem Link: SPREAD2 Problem - CodeChef