시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 1024 MB | 111 | 49 | 41 | 42.268% |
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.
4 1 6 7 12 3 5 10 11
21
2 1 2 1 1000000000
1999999998