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: 1360kB
In contest: 1075

#include<stdio.h>
void main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,m,i=0,total=0,t[100000],temp;
		scanf("%d %d",&n,&m);
		for(int j=1;j<=m;++j)
			scanf("%d",&t[j]);
		for(int q=1;q<m;++q)
		{
			for(int p=1;p<=m-q;++p)
			{
				if(t[p]>t[p+1])
				{
					temp=t[p];
					t[p]=t[p+1];
					t[p+1]=temp;
				}
			}
		}
		for(int j=1;j<=m;++j)
		{
			total+=t[j];
			if(total>n)
				break;
			else
				++i;
		}
		printf("%d\n",i);
	}
}