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()
{
	int t,n,m,x[101],i,total,h,j,z,temp;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&n,&m);
		if(n==0)
			printf("0\n");
		else
		{
			for(j=0;j<m;j++)
				scanf("%d",&x[j]);
			for(i=0;i<m-1;i++)
			{
				for(h=0;h<m-1;h++)
				{
					if(x[h]>x[h+1])
					{
						temp=x[h];
						x[h]=x[h+1];
						x[h+1]=temp;
					}
				}
			}
			total=0;
			for(z=0;z<m;z++)
			{
				total+=x[z];
				if(total<n)
					continue;
				else if(total>=n)
					break;
			}
			if(total>n)
				printf("%d\n",z);
			else if(total==n)
				printf("%d\n",z+1);
			else if(total<n)
				printf("%d\n",z);
		}
	}
}