AAAA 1 P2 - Heavy-Light Composition
View as PDFDaniel has found the perfect background and time of day for the perfect group photo. In this photo, he is trying out the newest photography technique: Heavy-Light Composition! To ensure the perfect composition for his photo, he has arranged his heavy-duty lights and
friends at unique positions across the number line. The
light is located at position
, while the
friend is located at position
.
Each light initially only illuminates its own position, but Daniel can repeatedly use one additional unit of power to extend the range of a light one position to the left OR one position to the right.
Formally, the light initially illuminates the interval
. Expanding the range of the
light to the interval
, where
, requires
units of power.
Daniel wants to make sure all of his friends are illuminated by at least one light, but electricity costs are heavy and his wallet is feeling light after buying all those heavy-duty lights! Thus, he would like you to determine the minimum amount of additional power needed to illuminate all his friends. Can you help him?
Constraints
All and
are distinct.
Subtask 1 [30%]
Subtask 2 [70%]
No additional constraints.
Input Specification
The first line contains two space-separated integers, and
, the number of heavy-duty lights and the number of friends, respectively.
The second line contains space-separated integers,
, the positions of the lights.
The third line contains space-separated integers,
, the positions of the friends.
Output Specification
Output one line containing one integer, the minimum amount of additional power Daniel needs to illuminate all his friends.
Sample Input 1
1 3
5
3 4 7
Sample Output 1
4
Sample Input 2
2 2
2 7
1 5
Sample Output 2
3
Sample Input 3
2 4
1 10
2 5 7 8
Sample Output 3
6
Comments