Start: Dec, 04, 2016 12:00:00
杭州师范大学第十届程序设计竞赛—正式
End: Dec, 04, 2016 17:00:00
Time elapsed:
Time remaining:

Problem_ID: B
Result: Accepted
Time: 2ms
Memory: 1700kB
In contest: 1075

#include<iostream>
#include<cstdlib>
using namespace std;
int comp(const void *p,const void *q){
		return (* reinterpret_cast<const int *>(p)-* reinterpret_cast<const int*>(q));
	}
int main(){
	int n,m,i,a[101],s,t;int b[101];
	int j,k;
	cin>>t;
	for(i=1;i<=t;i++)
	{
		scanf("%d%d",&m,&n);
		for(j=0;j<n;++j)
			cin>>a[j];
		qsort(a,n,sizeof(int),comp);
		int sum=0,z=0;
		for(k=0;k<n;k++)
		{
			sum+=a[k];
			if(sum>m)
				break;
			z++;
		}
		cout<<z<<endl;
	}
}