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;
		scanf("%d%d",&n,&m);
		int time=0;
		int girl[100];
		for(int i=0;i<m;i++){
			scanf("%d",&girl[i]);
			time+=girl[i];
		}
		if(time<=n)
			printf("%d\n",m);
		else{
			int pass,j,temp,k;
			for(pass=1;pass<m;++pass){
				for(j=0;j<m-pass;++j){
					if(girl[j]>girl[j+1]){
						temp=girl[j];
						girl[j]=girl[j+1];
						girl[j+1]=temp;
					}
				}
			}
			for(k=1;k<=m;k++){
				time-=girl[m-k];
				if(time<=n)
					break;
			}
			printf("%d\n",m-k);
		}
	}
	return 0;
}