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<string.h>
int main()
{
	int t,i,j;
	scanf("%d",&t);
	while(t--)
	{
		int m,n,num=0,time[101];
		scanf("%d%d",&n,&m);
		for(i=0;i<m;++i)
		{
			scanf("%d",&time[i]);
		}
		for(i=0;i<m;++i)
		{
			int temp;
			for(j=i+1;j<m;++j)
			{
				if(time[i]>time[j])
				{
					temp = time[i];
					time[i] = time[j];
					time[j] = temp;
 				}
			}
		}
		for(i=0;i<m;++i)
		{
			if(time[i]<=n)
			{
				num++;
				n-=time[i];
			}
			else
				break;
		}
		printf("%d\n",num);
	}
}