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