can someone tell why i am getting WA for this code?

#include<bits/stdc++.h>

using namespace std;

int main()

{

int t, k, j, i, t1, x, count, limit, rest, n, sum, sum1, ans, y, k1;

//cout<<"enter t ";

cin>>t;

while(t>0)

{

//cout<<"enter n and k ";

cin>>n>>k;

```
int arr[n], count=0, limit=1;
//cout<<"enter values"<<endl;
for(i=0; i<n; i++)
cin>>arr[i];
ans = 0;
sort(arr, arr+n);
for(i=0; i<k; i++)
ans = ans+arr[i];
for(y=1; y<=k; y++)
{
for(i=0; i<=n-k; i++)
{
sum = 0;
x=i;
for(j=0; j<y; j++)
{
//cout<<"i: "<<i<<" x: "<<x<<endl;
sum = sum+arr[x++];
}
if(sum > ans)
{
//cout<<"count: "<<count<<" limit: "<<y<<" sum: "<<sum<<" OUTER BREAK"<<endl;
break;
}
rest = k-y;
if(rest > 0)
{
t1 = y>1 ? x+1 : x;
for(t1; t1<n; t1++)
{
x = t1;
sum1 = sum;
for(k1=0; k1<rest; k1++)
{
//cout<<"i: "<<i<<" x: "<<x<<endl;
sum1 = sum1+arr[x++];
}
if(sum1 == ans)
{
count++;
//cout<<"count: "<<count<<" limit: "<<y<<" sum: "<<sum1<<" INNER"<<endl;
}
else
{
//cout<<"count: "<<count<<" limit: "<<y<<" sum: "<<sum1<<" INNER BREAK"<<endl;
break;
}
}
}
}
}
cout<<count<<endl;
t--;
}
return 0;
```

}