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