This page is still under construction.

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

Weights

Time limit3sMemory limit128 MB

Summary
Given container capacities and weights whose masses form a divisibility chain, maximize how many weights fit.
Level

Medium7 of 10

Topics
Greedy, Sorting, Math, Prefix sum
Solved
No attempts yet

Problem

The Byteotian Institute of Experimental Physics is moving to a new building, and transporting its large collection of precision weights has turned out to be tricky.

The Institute has a number of containers, each with a limited strength (the maximum total mass it can hold). We want to put as many weights as possible into the containers; any weights that do not fit are discarded. A container may hold any number of weights, as long as their total mass does not exceed its strength, and a container may also be left empty.

The weights have a special property: for any two of them, the mass of one is an integer multiple of the mass of the other (in particular, two weights may have equal mass).

Given the strengths of the containers and the masses of the weights, determine the maximum number of weights that can be placed into the containers.

Input

The first line contains two integers nn and mm (1≤n,m≤100 0001 \le n, m \le 100\,000): the number of containers and the number of weights.

The second line contains nn integers w1,w2,…,wnw_1, w_2, \ldots, w_n (1≤wi≤100 000 0001 \le w_i \le 100\,000\,000): the strengths of the containers, in milligrams.

The third line contains mm integers a1,a2,…,ama_1, a_2, \ldots, a_m (1≤aj≤1 000 000 0001 \le a_j \le 1\,000\,000\,000): the masses of the weights, in milligrams. For any two weights, one mass is an integer multiple of the other.

Output

Print a single integer: the maximum number of weights that can be placed into the containers without exceeding any container's strength.

Examples1

  1. Example 1

    Input
    2 4
    13 9
    4 12 2 4
    
    Expected output
    3