Time limit 1000/1000/1000/1000 ms. Memory limit 65000/65000/65000/65000 Kb.
Problem description
The mayor of Konya wants to build a science palace in the city. Since Konya has reach marble mines, the palace will have many marble columns. The columns can be monolithic (one piece stone) or consist of many smaller marble stones. Non-monolithic columns will be constructed by stacking the same type of marble stones. The stones differ only by their heights. Make a program to calculate minimum number of the stones needed to construct all the columns. There is always adequate number of stones from each kind.
Input
The first line contains two integers N (1<= N <= 100000) and M (1<= M <=100000). N denotes number of the columns and M denotes number of different types of stones that are available. There are N integers Ci (1 <= Ci <= 10000) in the second line; each of those numbers denotes height of a column. There are Si (1 <= Si <= 10000) distinct integers in the last line; each of those integers represents height of a stone type.
Output
Output should contain a single integer representing number of the stones necessary to construct all the columns. If it is not possible to construct all the columns, print “Impossible”.
Example
| stdin |
stdout |
4 6
8 5 15 12
2 5 10 4 3 10
|
9 |
1 2
9
5 4
|
Impossible |
Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.
|