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