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 flag,f,T,m,n,x,total;
	int pass,i,temp;
	int a[100];
	scanf("%d",&T);
	while(T--)
	{
		total=0;
		flag=0;
		scanf("%d %d",&n,&m);
		for(i=0;i<m;++i)
		{
		        scanf("%d",&x);
				a[i]=x;
		}
		for(pass=1;pass<m;++pass)
		{
			for(i=0;i<m-pass;++i)
			{
				if(a[i]>a[i+1])
				{
					temp=a[i];
					a[i]=a[i+1];
					a[i+1]=temp;
				}
			}
		}
		for(f=0;f<m;++f)
		{
			total+=a[f];
			if(total<=n)
				flag++;
			else
			    flag+=0;
		}

	    if(n==0||m==0)
			printf("0\n");
		else
		printf("%d\n",flag);
	}
	return 0;
}