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