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 = 0,i = 0,s = 0,n = 0,m = 0,c = 0,d= 0,count = 0,array[100],arr[100];
	scanf("%d ",&t);
	s = t;
	for(;t;--t)
	{
		scanf("%d %d",&n,&m);
		count =0;
		for(int j = 0;j<m;)
		{
			scanf("%d",&arr[j]);
			++j;
		}
		for(i = 0;i<m;++i)
		{
			for(int j= 0;j<m;++j)
			{
				if(arr[i]<arr[j])
				{
					c = arr[i];
					arr[i] = arr[j];
					arr[j] = c;
				}
			}
		}

		for(int j = 0;n>0 && m;)
		{
			n-=arr[j];
			++j;
			--m;
			if(n>=0)
			count ++;
		}
		array[t] = count;
	}
	for(;s;--s)
	{
		printf("%d\n",array[s]);
	}
	
}