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

#include<iostream>
#include<set>
using namespace std;

int main(){
	int t;
	cin>>t;
	
	while(t--){
		int n, m;
		int count = 0;
		int sum = 0;
		cin>>n>>m;
		int a[m];
		
		multiset<int>timeSet;
		
		for(int i=0; i<m; ++i){
			cin>>a[i];
		}
		
		timeSet.insert(a, a+m);
		
		set<int>::const_iterator pos;
		for(pos=timeSet.begin(); pos!=timeSet.end(); ++pos){
			sum += *pos;
			if(sum > n) break;
			count ++;
		}
		
		cout<<count<<endl;

	}
	
	return 0;
}