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 comp(const void * p,const void * q);
int main(void){
	int n,m,t;
	int sum,a[103],i,j;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
		sum=0;
		if(m==0)
		printf("0\n");
		else{
			for(i=0;i<m;i++){
		        scanf("%d",&a[i]);
		}
		qsort(a,m,sizeof(int),comp);
		for(j=0;j<m;j++){
			sum+=a[j];
			if(sum>n)break;
		}
		printf("%d\n",j);
		}	
	}
	return 0;
}
int comp(const void * p,const void * q){
	return (*(int * )p-*(int * )q);
}