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,n,m,l,a[100];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&n,&m);
		for(int i=0;i<m;++i)
		{
			scanf("%d",&a[i]);
		}
		int i,j;
		for(i=0;i<m;++i)
		{
			for(j=0;j<m-1;++j)
			{
				if(a[j]>a[j+1])
				{
					l=a[j];
					a[j]=a[j+1];
					a[j+1]=l;
				}
			}
		}
		int num=0,sum=0;
		for(i=0;i<m;++i)
		{
			sum+=a[i];
			if(sum>n)
			{
				break;
			}
			
		}
		printf("%d\n",i);
	}

	return 0;
}