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