代码如下
#include<bits/stdc++.h>
using namespace std;
const int N=100002;
int T,p=1;
int n,q,a[100005],k;
long long all;
double avg=1;
bool ch_a[100005];
bool check=true;
int del(int k,int num,long long now)
{
if(num==0) return 0;
if(!check) return num;
check=false;
avg=now/(double)num-k;
for(int i=p;i<=n;i++)
{
if(ch_a[i]&&a[i]>avg) break;
if(a[i]<avg&&!ch_a[i])
{
p++;
num--;
ch_a[i]=true;
now-=a[i];
check=true;
}
}
del(k,num,now);
}
int main()
{
cin>>T;
for(int i=1;i<=T;i++)
{
cin>>n>>q;
all=0;
for(int j=1;j<=n;j++) {cin>>a[j];all+=a[j];}
sort(a+1,a+n+1);
for(int j=1;j<=q;j++)
{
check=true;
memset(ch_a,0,sizeof(ch_a));
cin>>k;
// cout<<endl<<endl;
cout<<del(k,n,all)<<" ";
p=1;
}
cout<<endl;
}
return 0;
}