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*p,const void*q)
{
	return (*(int*)p-*(int*)q);
}
int main()
{
	int t,l;
	int k=0;
	int p[1000];
	scanf("%d",&t);
	while(t--)
	{		
		int n,m;
		int x=0,l=0;
		scanf("%d %d",&n,&m);
		for(int k=0;k<m;++k)
		{
			scanf("%d",&p[k]);
		}
			qsort(p,m,sizeof(int),comp);
			for(int k=0;k<m;++k)
			{
			x+=p[k];
			if(x<=n)
			{
				l+=1;
			}
			else
			{
				break;
			}
			}
		printf("%d\n",l);
	}
}