Result: Accepted
Time: 1ms
Memory: 1092kB
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int themin(int num,int A[]);
void main()
{
int t,i,time,num,j,every,A[100],k=0,x=0,count;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d%d",&time,&num);
for(j=0;j<num;j++){
scanf("%d",&every);
A[j]=every;}
count=0;
while(1)
{
time-=themin(num,A);
k++;
if(time<0)break;
count++;
}
printf("%d\n",count);
}
}
int themin(int num,int A[]){
int every,min=10000,j,k=100;
for(j=0;j<num;j++){
if(A[j]<min)
{min=A[j];
k=j;
}
}
A[k]=10000;
return min;
}