#P3462. Weight Transfer Optimization
Weight Transfer Optimization
Weight Transfer Optimization
While moving to a new compound, the Byteotian Institute of Experimental Physics encountered a logistical problem regarding the transfer of its vast collection of precision weights. They have a certain number of containers, each with a limited strength, and a collection of weights. The peculiarity is that for any two weights, the mass of one is an integer multiple of the mass of the other (in particular, some weights may be equal).
You are to put as many weights as possible into these containers with the restriction that the total mass in any container cannot exceed its strength. We may leave some weights unassigned (i.e. discarded) if they do not fit in any container. Your task is to compute the maximum number of weights that can be assigned to containers.
Note: If a container has a capacity C and you assign weights with masses w1, w2, …, wk to it, then you must have \(w_{1}+w_{2}+\cdots+w_{k} \le C\). Each weight can be used at most once.
inputFormat
The first line contains two integers n and m (n ≥ 1, m ≥ 1), where n is the number of containers and m is the number of weights.
The second line contains n space‐separated positive integers representing the strengths (capacities) of the containers.
The third line contains m space‐separated positive integers representing the masses of the weights.
outputFormat
Output a single integer — the maximum number of weights which can be put into the containers under the given constraints.
sample
2 3
10 5
2 4 8
3