Result: Accepted
Time: 1ms
Memory: 1092kB
#include<stdio.h>
int main(void){
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
int time=0;
int girl[100];
for(int i=0;i<m;i++){
scanf("%d",&girl[i]);
time+=girl[i];
}
if(time<=n)
printf("%d\n",m);
else{
int pass,j,temp,k;
for(pass=1;pass<m;++pass){
for(j=0;j<m-pass;++j){
if(girl[j]>girl[j+1]){
temp=girl[j];
girl[j]=girl[j+1];
girl[j+1]=temp;
}
}
}
for(k=1;k<=m;k++){
time-=girl[m-k];
if(time<=n)
break;
}
printf("%d\n",m-k);
}
}
return 0;
}