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>
void f(int a[],int b);
void main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n, m, a[101], b=0, c=0,d;
		scanf("%d%d",&n,&m);
		d=m;
		while(m--)
		{
			scanf("%d",&a[m]);
		}
		f(a,d);
		for(int o=0;o<=d;++o)
		{
			b=b+a[o];
			if(b>n)
				break;
			if(o==d)
				break;
			c++;
		}
		printf("%d\n",c);
	}
}
void f(int a[],int b)
{
	int p, i, t;
	for(p=1;p<b;++p)
	{
		for(i=0;i<b-p;++i)
		{
			if(a[i]>a[i+1])
			{
			t=a[i];
			a[i]=a[i+1];
			a[i+1]=t;
			}
		}
	}
}