Help me in solving Array Sum

include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t>0)
{

        int N,K;
        cin>>N>>K;

        int A[N];
        int sum=0;
        for(int i=0;i<N-1;i++)
        {
           if(i%2==0)
           A[i]=1;
           else
           A[i]=2;
           
          
           sum=sum+A[i];
        }
        A[N-1]=K-sum;
           int check = 0;
       if(A[N-1]<=0)
         {
                 check =1;
                 
         }
         if(A[N-1]%2==1)
         {
                 check = 1;
         }
         if (check == 1)
         cout<<"-1"<<endl;
         else
         {
              for(int i=0;i<N;i++)
         cout<<A[i]<<" "; 
         cout<<endl;
         }
       
        

        t--;
}
return 0;

}
I want to know that in what case the code is failing
problem link - Array Sum - Problems - CodeChef