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: 1360kB
In contest: 1075

#include<stdio.h>
#define arraysize 100000
void bubblesort(int list[],int arraySize);
int main(void){
	int T,n,m,i,a,total;
	int array[arraysize]={0};
	scanf("%d",&T);
	while(T--){
		total=0;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++)
		scanf("%d",&array[i]);
		bubblesort(array,i);
		for(a=0;a<i;a++){
		total+=array[a];
		if(total>n)
		break;
	}printf("%d\n",a);
	}return 0;
}void bubblesort(int list[],int arraySize){
	int pass,i,temp;
	for(pass=1;pass<arraySize;pass++){
		for(i=0;i<arraySize-pass;i++){
			if(list[i]>list[i+1]){
			temp=list[i];
			list[i]=list[i+1];
			list[i+1]=temp;
		}
		}
	}
}