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<stdlib.h>
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
	int n,m;
	scanf("%d %d",&n,&m);
	int i;
	int p[100];
	for(i=0;i<m;i++){
		scanf("%d",&p[i]);
	}
	int sum=0;
	int j=0;
	int pass,a,temp;
	for(pass=1;pass<m;++pass){
		for(a=0;a<m-pass;++a){
			if(p[a]>p[a+1]){
			temp=p[a];
			p[a]=p[a+1];
			p[a+1]=temp;
			}
		}
	}
	for(j=0;j<m;j++){
	if(sum+p[j]>n)
	   break;
	else
		sum+=p[j];
	}
	printf("%d\n",j);
	}
return 0;
}