I am getting WA (Wrong Answer) in this code. I passed all the sample test cases and also passed some self-created test cases. Please help!!
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int a=0;
int cases;
cin>>cases;
for(int i=0;i<cases;i++)
{
int n,k;
cin>>n>>k;
int m=2*(k+1);
if(m<=n)
{
int count1=0,count2=0;
vector<long long> arr(n);
int es=2*(k-1);
for(long long j=0;j<n;j++)
cin>>arr[j];
sort(arr.begin(),arr.end(), greater<int>());
for(int p=0;p<=es;p+=2)
{
count1=count1+arr[p];
if(p!=es)
count2=count2+arr[p+1];
else
count2=count2+arr[p+1]+arr[p+2];
}
if(count1>=count2)
cout<<count1<<endl;
else
cout<<count2<<endl;
}
else
cout<<a<<endl;
}
return 0;
}