#P2769. 猴子上树
猴子上树
Description
In Monkey Village, there is a straight mountain path that is very narrow, and its width can be ignored. There are monkeys standing on the path watching the students who came to compete today. Let a positive integer denote the position of the -th monkey; no two monkeys stand at the same position. There are tall trees planted at positions along this path. Let a positive integer denote the position of the -th tree; no two trees occupy the same position.
While the monkeys were intently admiring everyone's excellent programming skills, a tiger swaggered over. The monkeys broke into a cold sweat. Their first reaction was to find a tall tree to climb, which would help them avoid being bitten or eaten by the tiger (do not consider the tiger climbing trees).
If the monkey at position runs to the tree at position , the energy cost is . To make the most effective use of these trees for shelter, each tree must have at least one monkey. Please compute the minimum total energy required for all monkeys to climb onto trees.
Input Format
The input consists of 4 lines.
- Line 1: an integer , the number of monkeys.
- Line 2: integers; the -th integer is the position of the -th monkey.
- Line 3: an integer , the number of trees.
- Line 4: integers; the -th integer is the position of the -th tree.
Output Format
Output one line with a single integer: the minimum total energy required for all monkeys to climb onto trees.
3
1 4 5
2
3 8
6
3
3 1 10
2
8 3
4
Hint
For of the testdata, , .
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号