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<stdlib.h>
int cmp(const void*p,const void*q)
{
	return (*(int*)p-*(int*)q);
}
void main()
{
	int t,n,m,a[100],i,j;
	scanf("%d",&t);
	while(t--)
	{
		int sum=0;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++)
		{
			scanf("%d",&a[i]);
		}
		qsort(a,m,sizeof(int),cmp);
		for(i=0;i<m;i++)
		{
			sum+=a[i];
			if(sum>n&&i==0) break;
			else if(sum<=n&&n<(sum+a[i+1]))
				break;
			else if(sum<=n&&i==m-1)
				break;
		}
		if(sum>n&&i==0) printf("0\n");
		else
		printf("%d\n",i+1);
	}
	
}