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>
int main(){

	int a[101];
	int i,m,n,b,c,j,f,T;
	scanf("%d",&T);
	while(T--){
		b=0;
		c=0;
		f=0;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++){
			scanf("%d",&a[i]);
		}
		for(j=0;j<m-1;j++){
			for(i=0;i<m-1-j;i++){
				if(a[i]>a[i+1])
				{
					f=a[i];
					a[i]=a[i+1];
					a[i+1]=f;
				}
			}
		}
		
		for(i=0;i<m;i++){
		b+=a[i];
		if(b>n){
		break;
		}
		c++;
		}
		printf("%d\n",c);
	}
	return 0;
}