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()
{
	int T,n,m,time,a[111],b,c,d,e,mm,nn;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&n,&m);
		d=m;
		while(d--)
		{
		scanf("%d",&time);
		a[m-d]=time;
		}
		for(b=1;b<m;b++)
		{
			for(c=1;c<m-b+1;c++)
			{
				if(a[c]>a[c+1])
				{
					mm=a[c+1];
					a[c+1]=a[c];
					a[c]=mm;
				}
			}
		}
		nn=0;
		for(b=1;b<=m;b++)
		{
			nn=nn+a[b];
			if(nn>n)
			{
				printf("%d\n",b-1);
				break;
			}
			if(nn<=n&&b==m)
				printf("%d\n",b);
		}
	}
	return 0;
}