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

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int comp(const void *p, const void* q) {
	return (*(int *)p - * (int *)q);
}

int main() {
	int i, t, m, temp;
	float n;
	scanf("%d", &t);
	while(t--) {
		scanf("%f%d", &n, &m);
		float *a = (float *)malloc(sizeof(float) * m);
		for(i = 0; i < m; i++)
			scanf("%f", &a[i]);
		qsort(a, m, sizeof(float), comp);
		int count = 0;
		float sum = 0;
		for(i = 0; i < m; i++) {
			sum += a[i];
			if(sum <= n)
				count++;
			else
				break;
		}
		printf("%d\n", count);
	}
}