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>
#include<string.h>
int main(){
	int T,n,m,i,num,time,temp,pass,total,q;
	int ss[200];
	scanf("%d",&T);
	while(T--){
		scanf("%d %d",&n,&m);
		num=0;
		total=0;
		for(i=0;i<m;++i){
			scanf("%d",&time);
			ss[i]=time;
		}
		for(pass=1;pass<m;++pass){
			for(i=0;i<m-pass;++i){
				if(ss[i]>ss[i+1]){
					temp=ss[i];
					ss[i]=ss[i+1];
					ss[i+1]=temp;
				}
			}
		}
		for(q=0;q<m;++q){
			total+=ss[q];
			if(total<=n)
				num+=1;
		}
		printf("%d\n",num);
	}
	return 0;
}