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 t,i;
	scanf("%d",&t);
	for(i=0;i<t;++i){
		int n,m,j,k,t,l,sum=0,b;
		int a[100];
		scanf("%d%d",&n,&m);
		for(l=0;l<m;++l)
			scanf("%d",&a[l]);
		for(j=0;j<m-1;++j){
			for(k=0;k<m-1-j;++k){
				if(a[k]>a[k+1]){
					t=a[k];
					a[k]=a[k+1];
					a[k+1]=t;
				}
			}
		}
		for(b=0;sum<=n&&b<=m;++b){
			sum+=a[b];
		}
		printf("%d\n",b-1);
	}
	return 0;
}