题目描述
Problem Description
In the monkey village, there is a straight mountain path, which is very narrow and its width can be ignored. There are $n$ monkeys standing quietly on the path, observing the students participating in today's competition. An integer $X_i$ represents the position of the $i$-th monkey, and no two monkeys are standing at the same position. On this mountain path, there are $m$ tall trees planted at $m$ different positions, with an integer $Y_j$ representing the position of the $j$-th tree, and no two trees are at the same position.
While the monkeys are intently admiring the superb programming skills of the participants, a tiger walks by in a swagger. The monkeys are so frightened that they break into a cold sweat, and their first reaction is to find a tall tree to climb up to avoid being bitten or eaten by the tiger (assuming the tiger cannot climb trees).
A monkey at position $a$ running to a tree at position $b$ consumes energy equal to $|a-b|$ (the absolute value of $a-b$). To make the most efficient use of these trees for refuge, at least one monkey must climb each tree. Please calculate the minimum energy required for all $n$ monkeys to climb the trees.
Input Format
The input consists of 4 lines.
The first line contains an integer $n$, representing the number of monkeys.
The second line contains $n$ integers, where the $i$-th integer $X_i$ represents the position of the $i$-th monkey.
The third line contains an integer $m$, representing the number of trees.
The fourth line contains $m$ integers, where the $j$-th integer represents the position of the $j$-th tree.
Output Format
Output a single line containing an integer, which represents the minimum energy required for all $n$ monkeys to climb the trees.
Sample Input and Output
Sample Input #1
3
1 4 5
2
3 8
Sample Output #1
6
Sample Input #2
3
3 1 10
2
8 3
Sample Output #2
4
Notes
For 30% of the data, $1 \le n \le 500$, $1 \le X_i, Y_i \le 10^5$.
For 100% of the data, $1 \le n \le 5000$, $1 \le m \le n$, $1 \le X_i, Y_i \le 10^9$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分