#P5997. [PA 2014] Pakowanie

[PA 2014] Pakowanie

Description

You have nn items and mm bags. Each item has a weight and cannot be split; each bag has its own capacity. To pack all items into the bags, what is the minimum number of bags needed?

Input Format

The first line contains two integers n,mn, m, representing the number of items and the number of bags.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n, where aia_i is the weight of the ii-th item.

The third line contains mm integers c1,c2,,cmc_1, c_2, \ldots, c_m, where cic_i is the capacity of the ii-th bag.

Output Format

If it is possible to pack all items, output one integer representing the minimum number of bags used.

If it is not possible to pack all items, output NIE.

4 3
4 2 10 3
11 18 9
2

Hint

For 100%100\% of the testdata, 1n241 \le n \le 24, 1m1001 \le m \le 100, 1ai1081 \le a_i \le 10^8, 1ci1081 \le c_i \le 10^8.

Translated by ChatGPT 5