Start: Dec, 04, 2016 12:00:00
杭州师范大学第十届程序设计竞赛—正式
End: Dec, 04, 2016 17:00:00
Contest has ended!
Time elapsed: 05:00:00
Time remaining: 00:00:00

Problem_ID: B
Result: Accepted
Time: 1ms
Memory: 1092kB
In contest: 1075

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<stdio.h>
int main()
{
	int T,n,m;
	int a[120];
	int i,g,pass,temp,time,q;
	scanf("%d",&T);
	while(T--)
	{
		time=0;
		scanf("%d%d",&n,&m);
		if(m==0)
		{
			printf("0\n");
		}
		else
		{
					for(i=0;i<m;i++)
					{
						scanf("%d",&a[i]);
					}
		
					for(pass=1;pass<m;pass++)
					{
						for(g=0;g<m-pass;g++)
						{
							if(a[g]>a[g+1])
							{
								temp=a[g];
								a[g]=a[g+1];
								a[g+1]=temp;
							}
						}
					}
					for(i=0;i<m;i++)
					{
						time=time+a[i];
						if(time>n)
						{
							q=i;
							break;
						}
						else if(time==n)
						{
							q=i+1;
							break;
						}
						else
						{
							q=i+1;
						}
					}
					printf("%d\n",q);
		}
	}
}