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