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>
#include<string.h>
int main(){
	int m,n,sum,a[100],i,j,t,temp,b[100];
	scanf("%d",&t);
	while(t--){
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
		scanf("%d",&a[i]);
	for(i=0;i<m-1;i++){
		for(j=0;j<m-i-1;j++){
		temp=a[j];
		if(temp>a[j+1]){
		a[j]=a[j+1];
		a[j+1]=temp;
		
		}
		}}
	
	for(i=0;i<m;i++){
	     n-=a[i];
	    if(n<0)
			break;
	}
	
	printf("%d\n",i);
	}
return 0;
}