Maximum Product

0

0 votes
Medium-Hard
Problem

You are given an array of n natural numbers ai. And you are also given another array of k natural numbers bi(index starts from 1). You are asked to do given operation on the array:
Subtract ith number of the second array at ith step from any number of first array.
You have to do the above operation such that the mutual product ( a1a2a3...an ) of the final array is maximized after each operation.
It is guaranteed that there exists a sequence of given operations such that maximum product obtained after each operation is greater than zero.

INPUT:
On the first line, you are given two spaced natural numbers, n and k.
Next line contains n spaced integers(first array).
Next line contains k spaced integers(second array).

OUTPUT:
As the maximum product obtained can be much larger, output final maximum product % 1000000007.

CONSTRAINTS:
0 < n,k ≤ 106.
0 < ai,bi ≤ 109.

SAMPLE INPUT/OUTPUT:

INPUT:
6 3
9 7 10 12 5 4
8 7 6

OUTPUT:
5040

INPUT:
4 3
20 5 5 5
1 1 1

OUTPUT:
2125

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?