Logo
(追記) (追記ここまで)

24655번 - Coins and Boxes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB143655644.444%

문제

There are $N$ boxes and $N$ coins on the coordinate line. The coordinate of the $i$-th box is $B_i,ドル and the coordinate of the $j$-th coin is $C_j$. You are starting at the point with coordinate 0ドル,ドル 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 $N$ boxes. Find the minimum distance you need to travel to achieve your goal.

입력

The first line of input contains one integer $N$ (1ドル \le N \le 10^5$).

The second line contains $N$ integers $B_1, B_2, \ldots, B_N$. The $i$-th of those integers is coordinate of the $i$-th box (1ドル \le B_i \le 10^9,ドル $B_i < B_{i+1}$ for 1ドル \le i < N$).

The third line contains $N$ integers $C_1, C_2, \ldots, C_N$. The $i$-th of those integers is coordinate of the $i$-th coin (1ドル \le C_i \le 10^9,ドル $C_i < C_{i+1}$ for 1ドル \le i < N$).

출력

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

제한

예제 입력 1

4
1 6 7 12
3 5 10 11

예제 출력 1

21

예제 입력 2

2
1 2
1 1000000000

예제 출력 2

1999999998

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2022 > Day 1: Kyoto U Contest 2 C번

Contest > Open Cup > 2021/2022 Season > Stage 10: Grand Prix of Kyoto C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /