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