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 (void)
{
	int n,m,i,t,j,k,x,b;
	int a[1000];
	scanf("%d",&t);
	while(t--)
	{

		scanf("%d %d",&n,&m);
		for(i=0;i<m;++i)
			scanf("%d",&a[i]);
		for(j=0;j<m-1;++j)
		{
			for(i=m-1;i>j;--i)
			{
				if(a[i]<a[i-1])
				{
					k=a[i];
					a[i]=a[i-1];
					a[i-1]=k;
				}
			}
		}
				
		x=0;
		for(i=0;i<m;++i)
			{
				n=n-a[i];
			   if(n<0)
               {
				x=1;
				 printf("%d\n",i);
				break;
			  }
			
			    if(n==0)
              {
				x=1;
				 printf("%d\n",i+1);
				break;
			  }
		     }
		if(x==0)
	    printf("%d\n",m);
		
	}
	return 0; 
}