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)
{
	int a=*(int *)p;
    int b=*(int *)q;
	return a-b;
}
void main()
{
	int T,n,m,i,o,sum;
	int a[100];
	scanf("%d",&T);
	while(T--)
	{
		sum=0;
		scanf("%d %d",&n,&m);
		for(i=0;i<m;i++)
		{
			scanf("%d",&a[i]);
        }
		qsort(a,m,sizeof(int),comp);
		for(o=0;o<m;o++)
		{
			sum+=a[o];
			if(sum>n)
			{
				printf("%d\n",o);
				break;
			}
			else
			{
				continue;
			}
        }
		if(sum<=n)
		{
			printf("%d\n",m);
		}
	}
}