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,i,m,n,j,f;
	int x,y,z;
	scanf("%d",&T);
	int t[100];
	for(i=1;i<=T;++i)
	{
		scanf("%d %d",&n,&m);
		for(j=0;j<=m-1;++j){
		scanf("%d",&t[j]);
		}
		for(x=1;x<m;++x)
		{
			for(y=0;y<m-x;++y)
			{
				if(t[y]>t[y+1])
			{z=t[y];
				t[y]=t[y+1];
				t[y+1]=z;
			}
			}
		}
		for(f=0;f<m;++f)
		{
			n-=t[f];
		if(n<0)
			break;
		}
		printf("%d\n",f);
	}
	return 0;
}