아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Coins and Boxes

시간 제한2초메모리 제한1024 MB

요약
직선 위에 정렬된 N개의 상자와 N개의 동전이 있을 때, 각 상자에 동전 하나씩을 사용해 모든 상자를 열면서 0에서 출발하는 최단 이동 거리를 구한다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 투 포인터
정답자
아직 제출이 없습니다

문제

There are NN boxes and NN coins on the coordinate line. The coordinate of the ii-th box is B_iB\_i, and the coordinate of the jj-th coin is C_jC\_j. You are starting at the point with coordinate 00, 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 NN boxes. Find the minimum distance you need to travel to achieve your goal.

입력

The first line of input contains one integer NN (1≤N≤1051 \le N \le 10^5).

The second line contains NN integers B_1,B_2,…,B_NB\_1, B\_2, \ldots, B\_N. The ii-th of those integers is coordinate of the ii-th box (1≤B_i≤1091 \le B\_i \le 10^9, B_i<B_i+1B\_i < B\_{i+1} for 1≤i<N1 \le i < N).

The third line contains NN integers C_1,C_2,…,C_NC\_1, C\_2, \ldots, C\_N. The ii-th of those integers is coordinate of the ii-th coin (1≤C_i≤1091 \le C\_i \le 10^9, C_i<C_i+1C\_i < C\_{i+1} for 1≤i<N1 \le i < N).

출력

Print one integer: the minimum distance you need to travel to open all boxes.

예제2

  1. 예제 1

    입력
    4
    1 6 7 12
    3 5 10 11
    
    예상 출력
    21
    
  2. 예제 2

    입력
    2
    1 2
    1 1000000000
    
    예상 출력
    1999999998