I have doubt regarding my code

Whenever I submit my code I get the wrong answer.
Can anyone tell me what’s wrong with my code, where am I going wrong?
Code Chef Icecream: Contest Code:PRACTICE
Problem Code:CHFICRM

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 tc = sc.nextInt();

   while(tc !=0)
   {
       
       int sum[] =new int[1];
       int count =0;
       int N = sc.nextInt();
       int diff[] = new int[N];
       int a[] = new int[N];
       
       for(int j=0;j<N;j++)
       {
          a[j] = sc.nextInt();
          //System.out.println("a["+j+"]: "+ a[j]);
       }
       for(int j=1;j<N;j++)
       {
          if(a[0] == 5)
           {
             sum[0] = sum[0]+a[j-1];
             //System.out.println("sum["+0+"]: "+ sum[0]);
             diff[j-1] = a[j] - 5;
             if(diff[j-1] == a[j-1])
             {
                 count = count +1;
             }
             else if( diff[j-1] ==0 || a[j] == 5)
             {
               count= count+1;   
             }
             else if(a[j] == 15)
             {
                 if(sum[0]>=diff[j-1])
                 {
                     count = count +1;
                 }
                
             }
             
             if(j== (N-1) && count == (N-1))
             {
                     System.out.println("YES");
                    // System.out.println("if sum["+0+"]: "+ sum[0]);
                     sum[0] =0;
             }
             else if(count < (N-1) && j==(N-1))
             {
                 System.out.println("NO");
                 //System.out.println("sum["+0+"]: "+ sum[0]);
                 sum[0] =0;
             }
                 
             
             
            }
          else
            {
              System.out.println("NO");
              sum[0]=0;
            }
       }
   
       tc--;
   }
  
}

}

Can you try to explain the logic behind your approach?

thanks @micha_l for response, i figured it out. I understood where i was going wrong.