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<stdio.h>
#include<stdlib.h>

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		int n, m;
		scanf("%d %d", &n, &m);
		int time[101], size=0;
		for(int i=0; i<m; i++)
		{
			scanf("%d", &time[i]);
			size++;
		}
		
		int temp;
		for(int i=1; i<size; ++i){
			for(int j=0; j<size-i; ++j){
				if(time[j]>time[j+1]){
					temp=time[j];
					time[j]=time[j+1];
					time[j+1]=temp;
				}
			}
		}
		int count=0;
		for(int i=0; i<m; i++)
		{
			n=n-time[i];
			if(n>=0)
				count++;
			else
				break;
		}
		printf("%d\n",count);
	}
	
	
}