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 bubbleSort(int a[],int m);
int main()
{
	int T,n,m,h=0,k=0,total;
	int a[105];
	scanf("%d",&T);
	while(h<T)
	{
		scanf("%d %d",&n,&m);
		total = 0;
		for(k=0;k<m;++k)
		{
			scanf("%d",&a[k]);
		}
		bubbleSort(a,m);
		if(a[0]>n)
		{
			printf("0\n");
		}
		else
		{
			for(k=0;k<m;++k)
			{
				total = a[k] + total;
				if(total==n)
				{
					printf("%d\n",k+1);
					break;
				}
				if(total>n)
				{
					printf("%d\n",k);
					break;
				}
			}
			if(total<n)
			{
				printf("%d\n",k);
			}
		}
		++h;
	}
	return 0;
}
int bubbleSort(int a[],int m)
{
	int pass,i,temp;
	for(pass=1;pass<m;++pass)
	{
		for(i=0;i<m-pass;++i)
		{
			if(a[i]>a[i+1])
			{
				temp = a[i];
				a[i] = a[i+1];
				a[i+1] = temp;
			}
		}
	}
	return 0;
}