#P2945. Sand Castle Modification

    ID: 16203 Type: Default 1000ms 256MiB

Sand Castle Modification

Sand Castle Modification

Farmer John has built a sand castle with crenelated walls. The castle has N merlons (numbered 1..N) with varying heights. The height of the ith merlon is Mi (1 ≤ Mi ≤ 100,000). He has a list of target heights B1 through BN (1 ≤ Bi ≤ 100,000) and wishes to rearrange these targets in an optimal order for his castle.

Changing the height of a merlon costs money: raising the height costs X money per unit height increase, while lowering the height costs Y money per unit height decrease. Your task is to compute the minimum possible cost to adjust the castle by optimally permuting the target heights.

The cost for altering a merlon from height M to a target height B is computed as:

[ \text{cost} = \begin{cases} (B - M) \times X, & \text{if } B > M, \ (M - B) \times Y, & \text{if } B < M, \ 0, & \text{if } B = M. \end{cases} ]

It is optimal to sort both the current and target height arrays and pair them accordingly. The final answer is the sum of costs for each merlon, and it is guaranteed to fit within a 32-bit signed integer.

inputFormat

The input consists of three lines. The first line contains three integers: N, X, and Y, where N is the number of merlons, X is the cost per unit height increase, and Y is the cost per unit height decrease. The second line contains N integers, representing the current heights M₁, M₂, ..., Mₙ. The third line contains N integers, representing the target heights B₁, B₂, ..., Bₙ.

outputFormat

Output a single integer, the minimum possible cost for modifying the castle.

sample

3 5 3
3 1 4
2 5 3
10