The bored Bob is playing a number game. In the beginning, there are n numbers. For each turn, Bob will take out two numbers from the remaining numbers, and get the product of them. There is a condition that the sum of two numbers must be not larger than k.
Now, Bob is curious to know what the maximum sum of products he can get, if he plays at most m turns. Can you tell him?
Input
The first line of input contains a positive integer T, the number of test cases. For each test case, the first line is three integers n, m(0≤ n, m ≤100000) and k(0≤k ≤20000). In the second line, there are n numbers ai(0≤ ai ≤10000, 1≤ i ≤n).
Output
For each test case, output the maximum sum of products Bob can get.
Sample Input
2 4 2 7 1 3 2 4 3 2 3 2 3 1
Sample Output
14 2
/*
思路:对于一个数,每次肯定取满足条件的最大的数和他乘,然后取前m 大
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
#define bug printf("hihi\n")
#define eps 1e-8
using namespace std;
#define INF 0x3f3f3f3f
#define N 100005
multiset<int>s;
multiset<int>::iterator it;
int n,m,k;
int a[N];
int cmp(int a,int b)
{
return a>b;
}
void solve()
{
int i,j;
long long ans=0;
int cnt=0;
while(s.size()>=2)
{
it=s.end();
--it;
int x=*it;
s.erase(it);
it=s.upper_bound(k-x);
if(it==s.begin()) continue;
--it;
a[cnt++]=x*(*it);
s.erase(it);
}
sort(a,a+cnt,cmp);
for(i=0;i<m&&i<cnt;i++)
ans=ans+a[i];
printf("%lld\n",ans);
}
int main()
{
int i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
s.clear();
int x;
while(n--)
{
scanf("%d",&x);
s.insert(x);
}
solve();
}
return 0;
}