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*a,const void*b){
	return (*(int*)a-*(int*)b);
}
int main(){
	int i,t,n,m,s,x[10086];
	cin>>t;
	while(t--){
		cin>>n>>m;
		for(i=0;i<m;++i){
			cin>>x[i];
		}
		qsort(x,m,sizeof(int),comp);
		for(i=0;i<m;++i){
			if(n-x[i]>=0)
			n-=x[i];
			else break;
		}
		cout<<i<<endl;
		
	}
}