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