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,n,m,cc[10005]={0};
	scanf("%d",&T);
	while(T--){
		int temp=0,sum=0,ret=0;
		scanf("%d %d",&n,&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&cc[i]);
		}
		if(n==0||m==0)printf("0\n");
		else{
		for(int i=1;i<=m-1;i++){
			for(int j=1;j<=m-i;j++){
				if(cc[j]>=cc[j+1]){
				    temp=cc[j+1];cc[j+1]=cc[j];cc[j]=temp;
				}
			}
		}
		for(int i=1;i<=m;i++){
			if((sum+cc[i]>n))break;
			sum+=cc[i];ret++;
		}
		printf("%d\n",ret);
	}
	}
}