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>
int main(){
	int alltime,allgirls,i,j,re;
	int time[100],a;
	int t;
	scanf("%d",&t);
	while(t--){
		a=0;
		scanf("%d%d",&alltime,&allgirls);
		if(alltime==0||allgirls==0)
			printf("0\n");
		else 
		{
			for(i=0;i<allgirls;i++)
			     scanf("%d",&time[i]);
			for(j=0;j<allgirls;j++)
			{
				for(i=0;i<allgirls-1-j;i++)
				{  if(time[i]>time[i+1])
				   {re=time[i+1];
				time[i+1]=time[i];
				time[i]=re;}
				}
			}   
		//	for(i=0;i<allgirls;i++)
		//	     printf("%d",time[i]);
			for(i=0;i<allgirls;i++)
			{	a+=time[i];
				if(a==alltime)
				
				{printf("%d\n",i+1);
				break;}
			else if(a>alltime)
					{printf("%d\n",i);
				break;}
				else if(i==allgirls-1)
					printf("%d\n",i+1);
			}
		}
	}
	return 0;
}