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 t,i,a[101],n,m,j,tmp;
	j=0;
	scanf("%d",&t);
	while(t--){
	scanf("%d%d",&n,&m);
	  for(i=1;i<=m;i++){
	     scanf("%d",&a[i]);
	  }
	  for(i=1;i<m;i++){
		  for(j=i+1;j<=m;j++){
			  if(a[i]>=a[j]){
			  tmp=a[i];
			  a[i]=a[j];
			  a[j]=tmp;}
		  }}
	  for(j=1;j<=m;j++){
	     n=n-a[j];
		 if(n<0){
			 printf("%d\n",j-1);
			 break;
		 }
	  }if(n>=0){
	  printf("%d\n",j-1);}
	}
	return 0;
}