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 T;
scanf("%d",&T);
while(T--){
	int n,m,a,max,b,temp,d=0,e;
	int c[111];
	scanf("%d %d",&n,&m);
	for(a=0;a<m;a++)
	{
		scanf("%d",&c[a]);
	}
	for(a=0;a<m;a++)
	{
		for(b=0;b<m-a-1;b++)
		{
			if(c[b]>c[b+1])
			{
				temp=c[b+1];
				c[b+1]=c[b];
				c[b]=temp;
			}
		}
	}
	for(a=0;a<m;a++)
	{
		d+=c[a];
	     if(d>n)
	   {
		   e=a;
		   break;
	   }
	}
	if(d<=n)
	{e=m;
	}
	printf("%d\n",e);
}
}