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