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>

void sort(int a[], int len){
	int pass,w,tem;
	for(pass=1;pass<len;pass++){
		for(w=0;w<len-pass;w++){
			if(a[w]>a[w+1]){
				tem=a[w];
				a[w]=a[w+1];
				a[w+1]=tem;
			}
		}
	}
}
int main(){
	int a[100]={0},b[100]={0};
	int group,t_time, num_girl,time_girl,tem_time=0,t,j,i;
	scanf("%d",&group);
	for(t=0;t<group;t++){
		tem_time = 0;
		scanf("%d %d",&t_time,&num_girl);
		for( i=0;i<num_girl;i++){
			scanf("%d",&time_girl);
			a[i] = time_girl;
		}
		sort(a,i);
		for(j=0;j<num_girl;j++){
			tem_time+=a[j];
			if(tem_time>t_time)
				break;
			if(tem_time==t_time){
				j=j+1;
				break;
			}
		}
		b[t]=j;
	}
		for(int q=0;q<t;q++){
			printf("%d\n",b[q]);
		}
	return 0;
}