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;
    scanf("%d",&T);
    while(T--){
    int a[100];
    int n,m;
    scanf("%d%d",&n,&m);
    int i,k;
    for(i=0;i<m;i++){
    scanf("%d",&k);
    a[i]=k;
	}
	int c,d,e;
	for(c=1;c<m;c++){
	for(d=0;d<m-c;d++){
	if(a[d]>a[d+1]){
	e=a[d];
	a[d]=a[d+1];
	a[d+1]=e;
	}
	}
	}
	int count=0,sum=0;
	int f=0;
	while(sum<=n){
	if(f>m-1)
	break;
	sum+=a[f];
	if(sum>n){
	break;
}
	count++;
	f++;
	}
	printf("%d\n",count);
	}
	return 0;
}