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: 1700kB
In contest: 1075

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int comp(const void * p,const void * q){
	return (*(double *)p-*(double *)q);
}
int main(){
	int T;
	scanf ("%d",&T);
	int m;
	double n,num[1000];
	int i;
	while(T--){
		double total=0;
		int k;
		scanf("%lf%d",&n,&m);
		if(m==0)
		   k=0;
		else{
		  for(i=0;i<m;++i)
            scanf("%lf",&num[i]);
          qsort(num,m,sizeof(double),comp);   //从小到大排序 
          for(i=0;i<m;++i){
        	total+=num[i];
        	if(total-n>0){
        		k=i;
        		break;
			}
			k=i+1;
		  }
	    }
		printf("%d\n",k);
	}
}