Given n buildings of height
hn, the objective is to make every building has equal height. This can be done by removing bricks from a building or adding some bricks to a building. Removing a brick or adding a brick is done at certain cost which will be given along with the heights of the buildings. Find the minimal cost at which you can make the buildings look beautiful by reconstructing the buildings such that the n buildings satisfy
h3 = ... =
hn = k (k can be any number).
For convenience, all buildings are considered to be vertical piles of bricks, which are of same dimensions.
The first line contains number of buildings n (n ≤
105). The second line contains n integers which denotes the heights of the buildings
hn (0 ≤
hi ≤ 10000). The third line contains n integers
cn (0 ≤
ci ≤ 10000) which denotes the cost of adding or removing one unit of brick from the corresponding building.
Print the minimal cost to make all the buildings look beautiful.
4 2 3 1 4 10 20 30 40
3 1 2 3 10 100 1000