Help me in solving SUMARRAY problem

My issue

Here I was using a approach by printing “-1” if n is more than 2 times of k;
then according to the question half of the elements must be odd and other be even, i took half of the elements has 1 and the the other elements expect the last one as 0; and the last element was the difference of k and half of the elements which were 1;

My code

#include <bits/stdc++.h>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t--){
	    int n,k;
	    int a[n];
	    cin>>n>>k;
	    if(n>2*k){
	      cout<<"-1"<<endl;
	    }
	    else{
	        for(int i=0;i<n/2;i++){
	            a[i]=1;
	        }
	        for(int i=n/2;i<n-1;i++){
	            a[i]=0;
	        }
	        a[n-1]=k-(n/2);
	        for(int i=0;i<n;i++){
	            cout<<a[i]<<" ";
	        }
	        cout<<endl;
	    }
	    }
	return 0;
}

Problem Link: SUMARRAY Problem - CodeChef