| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 512 MB | 24 | 21 | 20 | 100.000% |
Consider a grid graph: the vertices are lined up into a grid of $H$ rows by $W$ columns. Let us denote the vertex in the $i$-th row and $j$-th column as $(i, j)$.
To define the weights of the graph edges, we will consider four non-decreasing sequences, $A,ドル $B,ドル $C,ドル and $D,ドル consisting of $H-1,ドル $W,ドル $H,ドル and $W-1$ positive integers, respectively:
Find the total weight of the edges in the minimal spanning tree of this graph.
The first line of input contains two positive integers $H$ and $W$ (2ドル \le H, W \le 10^5$).
The second line contains $H-1$ integers $A_i$: the elements of the sequence $A$.
The third line contains $W$ integers $B_i$: the elements of the sequence $B$.
The fourth line contains $H$ integers $C_i$: the elements of the sequence $C$.
The fifth line contains $W-1$ integers $D_i$: the elements of the sequence $D$.
It is guaranteed that $A_{i-1} \le A_{i},ドル $B_{i-1} \le B_{i},ドル $C_{i-1} \le C_{i},ドル and $D_{i-1} \le D_{i}$ for $i>1,ドル and additionally, 1ドル \le A_i, B_i, C_i, D_i \le 10^6$.
Print the total weight of the edges in the minimal spanning tree of the given graph. Note that the answer may not fit into a 32-bit integer.
2 3 1 1 3 6 1 4 1 2
17
4 3 1 13 15 3 6 11 3 6 6 11 9 17
173