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<string.h>
int main(void)
{
	int t,a[100],n,m,temp;
	int i,j,sum;
	scanf("%d",&t);
	while(t--)
	{
		sum=0;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;++i)
		{
			scanf("%d",&a[i]);
		}
			for(j=1;j<m;++j)
			{
				for(i=0;i<m-j;++i)
				{
					if(a[i]>a[i+1])
					{
						temp=a[i];
						a[i]=a[i+1];
						a[i+1]=temp;
					}
				}
			}
		for(i=0;i<m;++i)
		{
			sum+=a[i];
			if(sum<=n)
				continue;
			if(sum>n)
				break;
		}
		printf("%d\n",i);
	 }
	return 0;
}