Start: Dec, 04, 2016 12:00:00
杭州师范大学第十届程序设计竞赛—正式
End: Dec, 04, 2016 17:00:00
Time elapsed:
Time remaining:

Problem_ID: B
Result: Accepted
Time: 1ms
Memory: 1092kB
In contest: 1075

#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}


int main()
{
	int t, i, j, k, n, m, ans;
	int a[100];
	scanf("%d", &t);
	for (i = 0; i < t; i++)
	{
		scanf("%d%d", &n, &m);
		for (j = 0; j < m; j++)
		{
			scanf("%d", &a[j]);
		}
		qsort(a, m, sizeof(a[0]), comp);
		ans = 0;
		for (j = 0; j < m; j++)
		{
			if (n >= a[j])
			{
				n -= a[j];
				ans++;
			}
			else
			{
				break;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}