Skip to content

Grounding the Antennas

C31500
English

Language

Contribute a translation
Time limit
1000 ms
Memory limit
1024 MB
Submissions
3
Correct
3
Solved by
2
AC rate
100.000%

Statement

There are $N$ antennas positioned along a straight line at distinct integer coordinates $x_1 < x_2 < \cdots < x_N$.

A grounding system may contain either of the following connections:

  • Antenna $i$ may be connected directly to the ground at cost $A_{i}$.
  • Two antennas $i$ and $j$ may be connected by a cable at cost $|x_{i} - x_{j}|$.

An antenna is considered grounded if it is connected, possibly through other antennas and cables, to at least one antenna that is directly connected to the ground.

Determine the minimum total cost required to ground all $N$ antennas.

Input

The first line contains an integer $N$. ($1 \le N \le 200\,000$)

The second line contains $N$ integers $x_1,x_2,\ldots,x_N$, listed in strictly increasing order. ($0 \le x_1 < x_2 < \cdots < x_N \le 10^{9}$)

The third line contains $N$ integers $A_1,A_2,\ldots,A_N$, where $A_i$ is the cost of grounding antenna $i$ directly. ($1 \le A_i \le 10^{9}$)

Output

Output one integer: the minimum total cost required to ground every antenna.

Examples

Sample input 1
5
1 4 8 10 15
7 3 9 6 4
Sample output 1
16