PROBLEM: TWINGFT of today’s lunchtime…
Here is my solution…
#include <bits/stdc++.h>
using namespace std;
#define l1 long long
int main() {
l1 t;
cin>>t;
while(t--)
{
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
sort(arr, arr + n, greater<int>());
int first = 0, second = 0;
int index =arr[2*k];
for(int i=0;i<2*k;i=i+2)
{
first+=arr[i];
//cout<<arr[i];
}
for(int i=1;i<2*k;i=i+2)
{
second+=arr[i];
//cout<<arr[i];
}
second += index;
if(second>first)
cout<<second<<endl;
else
cout<<first<<endl;
}
return 0;
}
It is passing all given test cases but still showing WA on submission…
Please clear the logic along with the test cases at which my code is getting failed…
Here is some random code that matches exactly with mine
https://www.codechef.com/viewsolution/47271451