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
#include <cstdio>
#include <algorithm>

using namespace std;

int Packs[100];
bool PacksUsed[100];
int Items[24];
bool Used[24];

int main()
{
	int N, K;
	scanf("%d %d", &N, &K);
	for(int i = 0; i<N; i++) scanf("%d", &Items[i]);
	for(int i = 0; i<K; i++) scanf("%d", &Packs[i]);
	sort(Packs, Packs+K);
	sort(Items, Items+N);

	for(int i = K-1; i>=0; i--)
	{
		for(int j = N-1; j>=0; j--)
		{
			if(!Used[j])
			{
				if(Packs[i] >= Items[j])
				{
					Packs[i] -= Items[j];
					Used[j] = true;
					PacksUsed[i] = true;
				}
			}
		}
	}

	for(int i = 0; i<N; i++)
	{
		if(!Used[i])
		{
			printf("NIE\n");
			return 0;
		}
	}

	int res = 0;
	for(int i = 0; i<K; i++)
	{
		if(PacksUsed[i]) res++;
	}

	printf("%d", res);
	return 0;
}