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>
int main(void)
{
	int n,m,a[102],i,j,s,t,h,k,l;
	scanf("%d",&h);
	while(h--)
	{
		s=j=0;
		scanf("%d %d",&n,&m);
		for(i=0;i<m;++i)
			scanf("%d",&a[i]);
		for(i=1;i<m;++i)
		{
			for(l=0;l<m-i;++l)
			{
				if(a[l]>a[l+1])
				{
					t=a[l];
					a[l]=a[l+1];
					a[l+1]=t;
				}
			}
		}
		for(i=0;i<m;++i)
		{
			if(s<n)
			{
				s=s+a[i];
				j++;
			}
		}
		if(s>n)
				printf("%d\n",j-1);
		else
			printf("%d\n",j);
	}
	return 0;
}