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

#include<bits/stdc++.h>
using namespace std;

int comp(const void *p, const void *q) {
	return (*(int *)p - *(int *)q);
}
int main() {
	int T;
	cin >> T;
	while(T--) {
		int n, m;
		int time[100] = {0};
		int count = 0;
		cin >> n >> m;
		for(int i = 0; i < m; i++)
			cin >> time[i]; 
		qsort(time, m, sizeof(int), comp);
		int sum = 0;
		for(int i = 0; i < m; i++) {
			sum += time[i];
			if (sum > n)
				break;
			count++;
		}	
		cout << count << endl;
	}
	return 0;
}