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<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
vector<int>meizilist;
int main()
{
	int num;
	cin>>num;
	for(int i=0;i<num;i++)
	{
		int time,meizi_num,meet_num=0;
		cin>>time>>meizi_num;
		meizilist.resize(meizi_num);
		for(int i=0;i<meizi_num;i++)
		{
			cin>>meizilist[i];
		}
		sort(meizilist.begin(),meizilist.end());
		int it=0;
		while(it<meizilist.size())
		{
			time-=meizilist[it++];
			meet_num++;
			if(time==0)
				break;
			else if(time<=0)
			{
				meet_num--;
				break;
			}
		}
		cout<<meet_num<<endl;
	}

}