Result: Accepted
Time: 1ms
Memory: 1092kB
#include<stdio.h>
int main()
{
int t, n, m, count = 0, countAll = 0;
int temp;
int a[10005], b[105];
b[0] = 0;
scanf("%d", &t);
for(int i = 0; i < t; i++)
{
b[i] = 0;
scanf("%d %d", &n, &m);
for(int j = 0; j < m; j++)
scanf("%d", &a[j]);
for(int j = 1; j < m; j++)
{
for(int k = 0; k < m - j; k++)
{
if(a[k] > a[k + 1])
{
temp = a[k];
a[k] = a[k + 1];
a[k + 1] = temp;
}
}
}
for(int j = 0; j < m; j++)
{
countAll += a[j];
if(countAll <= n)
count++;
}
b[i] = count;
count = 0;
countAll = 0;
}
for(int i = 0; i < t; i++)
printf("%d\n", b[i]);
}