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