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<stdio.h>
#include<stdlib.h>
using namespace std;
int main(){
	int t;
	int n , m;
	cin>>t;
	while(t--){
		cin>>n>>m;
		int *a = (int *)malloc(sizeof(int)*m);
		for(int i=0;i<m;++i){
			cin>>a[i];
		}
		for(int i=0;i<m;++i){
			for(int j = 0; j<i;++j){
				if(a[j]>a[i]){
					int temp = a[j];
					a[j] = a[i];
					a[i] = temp;
				}
			}
		}
		int all=0;
		for(int i=0;i<m;++i){
			n=n-a[i];
			if(n>=0){++all;}
			else{break;}
		}
		printf("%d\n",all);
		free(a);
	}
}