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