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>
#include<stdlib.h>
void mp(int a[],int n)
{
	int i,j,t;
	for(j=1;j<n;j++)
	{
		for(i=0;i<n-j;i++)
		{
			if(a[i]>a[i+1])
			{
				t=a[i];
				a[i]=a[i+1];
				a[i+1]=t;
			}
		}
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m;
		scanf("%d%d",&n,&m);
		int *a;
		a=(int*)malloc(sizeof(int)*m);
		int x,i;
		for(i=0;i<m;i++)
		{
			scanf("%d",&x);
			a[i]=x;
		}
		mp(a,m);
		int mz=0,s=0;
		for(i=0;i<m;i++)
		{
			s+=a[i];
			if(s<=n)
				mz++;
		}
		printf("%d\n",mz);
	}
	return 0;
}