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(void){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,m,i,sum=0;
		scanf("%d%d",&n,&m);
		int a[m];
		for(i=0;i<m;i++){
			scanf("%d",&a[i]);
			}
		int p,q,tm;
	    for(p=1;p<m-1;p++)
	    	for(q=0;q<m-p;q++){
	    		if(a[q]>a[q+1]){
	    			tm=a[q];
	    			a[q]=a[q+1];
	    			a[q+1]=tm;
				}
			}
		for(i=0;i<m;i++){
			sum+=a[i];
			if(sum>n){
			printf("%d\n",i);
			break;
		    }
			else if(sum==n){
			printf("%d\n",i+1);
			break;
		    }
			else if(sum<n&&i+1==m)
			printf("%d\n",m);
			}
		}
		return 0;
	}