Problem Statement
There are $N$ monsters along a number line. At the coordinate $i$ $(1\leq i\leq N)$ is a monster with a stamina of $A_i$.
Additionally, at the coordinate $i$, there is a permanent shield of a strength $B_i$.
This shield persists even when the monster at the same coordinate has a health of $0$ or below.
Takahashi, a magician, can perform the following operation any number of times.
- Choose integers
$l$and$r$satisfying$1\leq l\leq r\leq N$. - Then, consume
$\max(B_l, B_{l+1}, \ldots, B_r)$MP (magic points) to decrease by$1$the stamina of each of the monsters at the coordinates$l,l+1,\ldots,r$.
When choosing $l$ and $r$, it is fine if some of the monsters at the coordinates $l,l+1,\ldots,r$ already have a stamina of $0$ or below.
Note, however, that the shields at all those coordinates still exist.
Takahashi wants to make the stamina of every monster $0$ or below.
Find the minimum total MP needed to achieve his objective.
Constraints
$1 \leq N \leq 10^5$$1 \leq A_i,B_i \leq 10^9$- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
Output
Print the minimum total MP needed to achieve his objective.
样例
5
4 3 5 1 2
10 40 20 60 50
210
1
1000000000
1000000000
1000000000000000000
10
522 4575 6426 9445 8772 81 3447 629 3497 7202
7775 4325 3982 4784 8417 2156 1932 5902 5728 8537
77917796
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。