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