#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
multiset<int>S;
vector<int>vec;
bool cmp(int a,int b){
return a>b;
}
int main()
{
int t,i,j,n,m,k;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
int num;
S.clear();vec.clear();
for(i=0;i<n;++i){
scanf("%d",&num);
if(num<=k)S.insert(-num);
}
while(1){
if(S.size()<2)break;
num=*(S.begin());
S.erase(S.begin());
multiset<int>::iterator it=S.lower_bound(-k-num);
if(it!=S.end()){
vec.push_back((*it)*num);
S.erase(it);
}
}
sort(vec.begin(),vec.end(),cmp);
long long sum=0;
for(i=0;i<vec.size()&&i<m;++i){
sum+=vec[i];
}
printf("%lld\n",sum);
}
return 0;
}
zoj3908Number Game
最新推荐文章于 2022-10-21 16:54:07 发布