Coins and Boxes
시간 제한2초메모리 제한1024 MB
직선 위에 정렬된 N개의 상자와 N개의 동전이 있을 때, 각 상자에 동전 하나씩을 사용해 모든 상자를 열면서 0에서 출발하는 최단 이동 거리를 구한다.
문제
There are boxes and coins on the coordinate line. The coordinate of the -th box is , and the coordinate of the -th coin is . You are starting at the point with coordinate , and can move freely along the coordinate line.
If you go to a point with a coin, you can pick up that coin. You can carry as many coins as you like. If you go to a point with the box, you can utilize one coin and open the box (but you are not forced to do that). You cannot pick up the coin that was already picked up, or open the box that is already opened.
You want to open all boxes. Find the minimum distance you need to travel to achieve your goal.
입력
The first line of input contains one integer ().
The second line contains integers . The -th of those integers is coordinate of the -th box (, for ).
The third line contains integers . The -th of those integers is coordinate of the -th coin (, for ).
출력
Print one integer: the minimum distance you need to travel to open all boxes.