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(void){
	int t;
	int a,b;
	int i;
	int pass,temp;
	int total;
	int num[100];
	scanf("%d",&t);
	while(t--){
		total=0;
		scanf("%d%d",&a,&b);
		for(i=0;i<b;++i)
			scanf("%d",&num[i]);
		if(b>1){
		for(pass=1;pass<b;++pass){
			for(i=0;i<b-pass;++i){
				if(num[i]>num[i+1]){
					temp=num[i];
					num[i]=num[i+1];
					num[i+1]=temp;
				}
			}
		}
		}
		for(i=0;i<b;++i){
			total+=num[i];
			if(total>a){
				printf("%d\n",i);
				break;
			}
			if(total==a){
				printf("%d\n",i+1);
				break;
			}
		}
		if(total<a)
			printf("%d\n",b);
	}
 return 0;
}