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 bubblesort(int list[],int arraysize);
void printarray(const int list[],int arraysize);
int main(void)
{
	int t,n,m,j,k,sum;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&n,&m);
		int list[m];
		int array[m];
		for(j=0;j<m;++j)
		{
			scanf("%d",&list[j]);
		}
	    bubblesort(list,m);
	    sum=0;
	    for(k=0;k<m;++k)
	    {
	    	sum+=list[k];
	    	if(sum>n) 
	    	{
	    		printf("%d\n",k);
	    		break;
			}
		}
		if(sum<=n) printf("%d\n",m);
	    
	}

	return 0;
}
void bubblesort(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;
			}	
		}
	}
}