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 a,b,c,e,f,d[101],s,n,m;
	scanf("%d",&a);
	while(a--)
	{   
		e=0;
		scanf("%d %d",&b,&c);
		for(f=0;f<c;++f)
		{
			scanf("%d",&d[f]);	  
		} 
		for(s=1;s<f;++s)
		{
			for(int i=0;i<f-s;++i)
			{
				if(d[i]>d[i+1])
				{
					n=d[i];
					d[i]=d[i+1];
					d[i+1]=n;
				}
			}
		}
		for(m=0;m<c&&e<=b;++m)
			{
				e=e+d[m];
			} 
			if(e<=b)
				printf("%d\n",m);
			else if(e>b)
				printf("%d\n",m-1);	
}
	return 0;
}