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>
void bubble(int list[],int m);
int main(void) {
	int T,sum,num;
	int list[100];
	scanf("%d",&T);
	while(T--) {
	scanf("%d%d",&sum,&num);
	for(int i=0;i<num;i++) {
		scanf("%d",&list[i]);
	}
	bubble(list,num);
	int people=0,left=sum;
	for(int m=0;m<num;m++) {
		left-=list[m];
		if(left>=0)
			people++;
		else
			break;
	}
	printf("%d\n",people);
	}
}
void bubble(int list[],int m) {
	int p,i,temp;
	for(p=1;p<m;p++) {
		for(i=0;i<m-p;i++) {
			if(list[i]>list[i+1]) {
				temp=list[i];
				list[i]=list[i+1];
				list[i+1]=temp;
			}
		}
	}
}