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>
void bubbleSort(int list[],int m);
int main(void)
{
	int T;
	int n,m;
	int a[10000]={0};
	scanf("%d",&T);
	while(T--)
	{
		int k=-1;
		int time=0;
		scanf("%d",&n);
		scanf("%d",&m);
		int i;
		for(i=0;i<m;i++)
		{
			scanf("%d",&a[i]);
		}
		
		bubbleSort(a,m);
		
		while((time<=n)&&(k<m))
		{
			k=k+1;
			time=time+a[k];
			
		}

		printf("%d",k);
		printf("\n");
	}
	return 0;
}
void bubbleSort(int list[],int m)
{
	int pass,i,temp;
	for(pass=1;pass<m;++pass){
		for(i=0;i<m-pass;++i){
			if(list[i]>list[i+1])
			{
				temp=list[i];
				list[i]=list[i+1];
				list[i+1]=temp;
			}
		}
	}
}