In problem TWINGFT
can anyone please help me that why this code is giving me the wrong answer on submission …while I have the same logic with editorial’s solutions…It is giving me the right answer on normal compile and run but giving the wrong answer on submission
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int t;
cin>>t;
while(t–)
{
int n,k;
cin>>n>>k;
ll a[n+1],first=0,second=0;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a,a+n+1, greater<int>());
for(int i=1;i<=2*k;i++ )
{
if((i%2)!=0)
{
first+=a[i];
}
else
{
second+=a[i];
}
}
second+=a[2*k+1];
cout<<max(first,second)<<endl;
}
return 0;
}