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>
void sort(int list[],int ArraySize)
{
	int pass,i,temp;
	for(pass=1;pass<ArraySize;++pass)
	{
		for(i=0;i<ArraySize-pass;++i)
		{
			if(list[i]>list[i+1])
			{
				temp=list[i];
				list[i]=list[i+1];
				list[i+1]=temp;
			}
		}
	}
}

int main()
{
	int t;
	int n,m;
	int a[100];
	int total=0;
	scanf("%d",&t);
	int i,j,k;
	for(i=0;i<t;i++)
	{
		scanf("%d%d",&n,&m);
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[j]);
		}
		sort(a,m);
		for(k=0;k<m;k++)
		{
			total+=a[k];
			if(total>n)
				break;
		}
		printf("%d\n",k);
		total=0;
	}
	return 0;
	
}