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 str[110],int d){
	int t, m,i;
	m=d-1;
	while(m--){
	for(i=0;i<=m;i++){
		if(str[i]>=str[i+1]){
		t=str[i];
		str[i]=str[i+1];
		str[i+1]=t;
			}
		}
	}
	
}

int main(){
	int n, m, t, a, b, c, d,e,i;
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &m);
		int str[110];
		d=m;
		c=0;
		for(b=0;b<m;b++){
			scanf("%d", &a);
			str[b]=a;
		}
		e=0;
		sort(str,d);
		for(i=0;i<d;i++){
			c+=str[i];
			if(c<=n)
				e++;
		}
		printf("%d\n",e);
	}
	return 0;
}