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