Result: Accepted
Time: 1ms
Memory: 1092kB
# include <stdio.h>
int main()
{
int t = 0,i = 0,s = 0,n = 0,m = 0,c = 0,d= 0,count = 0,array[100],arr[100];
scanf("%d ",&t);
s = t;
for(;t;--t)
{
scanf("%d %d",&n,&m);
count =0;
for(int j = 0;j<m;)
{
scanf("%d",&arr[j]);
++j;
}
for(i = 0;i<m;++i)
{
for(int j= 0;j<m;++j)
{
if(arr[i]<arr[j])
{
c = arr[i];
arr[i] = arr[j];
arr[j] = c;
}
}
}
for(int j = 0;n>0 && m;)
{
n-=arr[j];
++j;
--m;
if(n>=0)
count ++;
}
array[t] = count;
}
for(;s;--s)
{
printf("%d\n",array[s]);
}
}