This page is still under construction.

Parts of this page are still being built. What you see may change.

Packing

Time limit1sMemory limit256 MB

Summary
Buy the fewest backpacks from the shop so all items fit without splitting items or exceeding capacities.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

Camping season is here. A trip needs all sorts of gear, and you carry that gear yourself, so deciding what you really need matters. The gear is already picked out, so the only thing left is to pack it into backpacks.

One backpack takes any number of items, as long as their total weight does not exceed its capacity. Items cannot be split, so part of the capacity you buy may go unused.

The catch is that you own no backpacks yet and have to buy them. The shop sells backpacks of several capacities, and they all cost the same. Buy enough backpacks to hold every item while spending as little as possible.

Input

The first line contains the number of items to pack, nn, and the number of backpacks in the shop, mm. (1≤n≤241 \le n \le 24, 1≤m≤1001 \le m \le 100)

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n. The value aia_i is the weight of the ii-th item. (1≤ai≤1081 \le a_i \le 10^8)

The third line contains mm integers c1,c2,…,cmc_1, c_2, \dots, c_m. The value cic_i is the capacity of the ii-th backpack. (1≤ci≤1081 \le c_i \le 10^8)

Output

Print on the first line the minimum number of backpacks that hold every item. If packing every item is impossible, print the word NIE instead.

Hint

In the first example you can buy the first backpack and the third backpack. The heaviest item goes into the backpack of capacity 11, and the remaining items go into the backpack of capacity 9.

Examples2

  1. Example 1

    Input
    4 3
    4 2 10 3
    11 18 9
    
    Expected output
    2
    
  2. Example 2

    Input
    1 1
    5
    4
    
    Expected output
    NIE