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

sort(arr, arr + n, greater());
it shoud be

``````sort(arr, arr + n, greater<int>());  (int is missing  in bracket )

``````

And also while pasting your code in comment section bro you should
enclose your code in 3 double ticks(```) like this →

``````This is a sample code
``````

@dassault_rafel
`sort(arr, arr + n, greater<int>()); `
I have written this statement correctly you can see my code but still getting WA.

ok let me see bro

``````#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
ll t;
cin>>t;
while(t--)
{
ll n, k;
cin >> n >> k;
ll arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
sort(arr, arr + n, greater<ll>());
ll first = 0, second = 0;
ll index =arr[2*k];

for(ll i=0;i<2*k;i=i+2)
{
first+=arr[i];
//cout<<arr[i];
}
for(ll 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;
}``````

change int to long long and no need to write l1 you can write it ll that will not cause confusion…
and I have written corrected code above.

@sanjay_1 bro, try to use long long int.
because the array element size is of order 10^9 and you are taking its sum which will be more than 10^9, which on storing in int will give error.

I recommend changing the int to some other data type like mentioned.

ur getting int overflow replace the data type of first and second variable to long long int