Help me in solving ATM2 problem

My issue

what is error in my code?

My code

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		while(n>0){
		    int k=sc.nextInt();
		    int N=sc.nextInt();
		    int [] a=new int[k];
		    for(int i=0;i<k;i++){
		        a[i]=sc.nextInt();
		    }
		    int t=0;
		    for(int i=0;i<k;i++){
		        if(a[i]>N){
		            System.out.print("0");
		        }
		        else{
		            t=t+a[i];
		            if(t<=N){
		                System.out.print("1");
		            }
		            else{
		                System.out.print("0");
		            }
		            
		        }
		    }
		}

	}
}

Problem Link: ATM Machine Practice Coding Problem - CodeChef

@ace0586
plzz refer the follwing c++ code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n>>k;
	    int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        if(a[i]<=k)
	        {
	            cout<<1;
	            k-=a[i];
	        }
	        else
	        cout<<0;
	    }
	    cout<<endl;
	}
	return 0;
}

refer my python code

# cook your dish here
for i in range(int(input())):
    m,n = map(int,input().split())
    a = [int(a) for a in input().split()]
    s=''
    for x in range(m):
        if n == 0:
            s=s+('0'*(m-x))
            break
        else:
            if a[x] <= n:
                n-=a[x]
                s+='1'
            else:
                s+='0'
           
    print(s)