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 mp(int g[],int n);
int main(void)
{
	int t,n,m,g[1000],count,i,sum;
	scanf("%d",&t);
	while(t--)
	{
		count=0;
		sum=0;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++)
		{
			scanf("%d",&g[i]);
		}
		mp(g,m);
		for(i=0;i<m;i++)
		{
			sum+=g[i];
			if(sum>n)
			break;
			count++;
		}
		printf("%d\n",count);
	}
}
int mp(int g[],int m)
{
	int pass=1,i,temp;
	for(pass=1;pass<m;++pass)
	{
		for(i=0;i<m-pass;++i)
		{
			if(g[i]>g[i+1])
			{
				temp=g[i];
				g[i]=g[i+1];
				g[i+1]=temp;
			}
		}
	}
}