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>
#include<stdlib.h>
#include<math.h>
/*int sort(int array[],int m){
	int k,pass ; 
		for(pass=1;i<m;++pass){
			for(j=0;j<m-pass;++j){
				if(array[j]>array[j+1]){
					k=array[j];
					array[j]=array[j+1];
					array[j+1]=k;
				}
			}
		}
}*/
int main(){
	int t;
	int i,j;
	int m,n,sum;
	scanf("%d",&t);
	while(t--){
		int array[100];
	    scanf("%d %d",&n,&m);
		for(i=0;i<m;i++){
			scanf("%d",&array[i]);
		}
		int k,pass ; 
		for(pass=1;pass<m;++pass){
			for(j=0;j<m-pass;++j){
				if(array[j]>array[j+1]){
					k=array[j];
					array[j]=array[j+1];
					array[j+1]=k;
				}
			}
		}
		sum = 0;
		int count =0;
		for(i=0;i<m;i++){
			sum+=array[i];
			    if(sum>n)
				   break;
				else
					count++;
		}
			printf("%d\n",count);
	}
	//system("pause");
	return 0;
		
	}