No.1767 BLUE to RED
Problem Statement
ALiCE found a grid of $10^{100}$ cells arranged in a horizontal row. The $A_1,A_2,\dots,A_N$-th cells from the left are red, the $B_1,B_2,\dots,B_M$-th cells from the left are blue, and all other cells are white.
ALiCE dislikes blue, so she wants to eliminate all blue cells by repeating the following operation $0$ or more times.
- Choose a cell adjacent to some red cell, and change the color of that cell to red.
Find the minimum number of operations required for ALiCE to achieve her goal.
Input
$N$ $M$ $A_1$ $A_2$ $\dots$ $A_N$ $B_1$ $B_2$ $\dots$ $B_M$
- All inputs are integers.
- $1 \le N,M \le 2 \times 10^5$
- $1 \le A_i,B_i \le 10^9$
- $A_i \lt A_{i+1}$
- $B_i \lt B_{i+1}$
- $A_1,A_2,\dots,A_N,B_1,B_2,\dots,B_M$ are all distinct.
Output
Output the minimum number of operations required for ALiCE to achieve her goal, followed by a newline.
Sample
Sample 1
Input
5 2 1 3 14 19 20 6 15
Output
4
The minimum number of operations, $4$, can be achieved by operating as follows.
- Paint cell $4$, adjacent to cell $3$, red.
- Paint cell $5$, adjacent to cell $4$, red.
- Paint cell $6$, adjacent to cell $5$, red.
- Paint cell $15$, adjacent to cell $14$, red.
Sample 2
Input
7 10 4 16 18 20 22 37 99 6 7 29 38 55 64 68 70 92 97
Output
50
Sample 3
Input
1 20 7 24 25 26 32 40 41 46 53 59 60 64 74 81 85 90 93 95 98 99 100
Output
93
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
sak