Problem Link: SUMARRAY Problem - CodeChef

### Feedback

Can anyone please tell what’s wrong with my solution, It’s giving a Wrong answer for the 2nd testcase.

Logic - Firstly i am checking if the array is possible or not by taking 1,2,1,… as inputs in the array until n-1th position and then calculating the last element required to get the desired sum. If the last element required makes the number of odd and even elements equal, the array is possible.

Code -

include <bits/stdc++.h>

using namespace std;

int main() {

int t,n,k;

```
cin>>t;
while(t--)
{
cin>>n>>k;
int odd=1;
int even=2;
int ans=odd*(n/2)+even*(n/2-1);
int res=k-ans;
if(res%2==0 && res>0)
{
int avg=k/n;
for(int i=0;i<(n/2);i++)
cout<<avg<<" ";
for(int i=0;i<(n/2)-1;i++)
cout<<avg-1<<" ";
res=k-(avg*n/2)-((avg-1)*((n/2)-1));
cout<<res<<endl;
}
else
cout<<-1<<endl;
}
return 0;
```

}