Result: Accepted
Time: 1ms
Memory: 1700kB
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int comp(const void * p,const void * q){
return (*(double *)p-*(double *)q);
}
int main(){
int T;
scanf ("%d",&T);
int m;
double n,num[1000];
int i;
while(T--){
double total=0;
int k;
scanf("%lf%d",&n,&m);
if(m==0)
k=0;
else{
for(i=0;i<m;++i)
scanf("%lf",&num[i]);
qsort(num,m,sizeof(double),comp); //从小到大排序
for(i=0;i<m;++i){
total+=num[i];
if(total-n>0){
k=i;
break;
}
k=i+1;
}
}
printf("%d\n",k);
}
}