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 n,m,i,t,j,temp,sum;
	int num[100];
	scanf("%d",&t);
	while(t--){
	scanf("%d %d",&m,&n);
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	for(j=1;j<n;j++){
		for(i=0;i<n-1;i++)
			if(num[i]>num[i+1]){
				temp=num[i];
				num[i]=num[i+1];
				num[i+1]=temp;
			}
	}
	sum=0;
	for(i=0;i<n;i++){
		sum+=num[i];
		if(sum>m)
			break;
	}
	printf("%d\n",i);
	}

	return 0;
}