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

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

#include<stdio.h>
#include<stdlib.h>
#define ARRAY_SIZE 100
int comp(const void*p,const void*q)
{
return (*(int*)p-*(int*)q);
}
int main()
{
	int t,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{
	int n,m,x,people=0;
	int list[ARRAY_SIZE];
	scanf("%d %d",&n,&m);
		for(x=0;x<m;x++)
		{
            scanf("%d",&list[x]);
		}
qsort(list,m,sizeof(int),comp);
	for(x=0;x<m;x++)
	{
		n-=list[x];
		if(n>=0)
            people++;
		else
			break;
	}
	printf("%d\n",people);
}
return 0;
}