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<math.h>

int main(void){
	int time[1000];
	int T,n,m,a,b;
	int i,j,c;
	int newtime;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		c=m;
		for(i=0;i<m;i++){
    		scanf("%d",&a);
			time[i]=a;
		}
		while(m--){
			
    		for(i=1;i<c;i++){
    			newtime=time[i-1];
    			if(time[i]<time[i-1]){
     				time[i-1]=time[i];
    				time[i]=newtime;
				    
	    		}
    		}
        }
		b=0;
		for(i=0;i<c;i++){
			n=n-time[i];
			if(n<0)
				break;
			else
				b++;
		}
		printf("%d\n",b);
	}
	return 0;
}