問題一覧 > 通常問題

No.1767 BLUE to RED

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 121
作問者 : first_vil / テスター : ygussany sak
お気に入りにしたユーザー ProblemId : 7034 / 自分の提出
問題文最終更新日: 2021-11-26 14:45:12
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 325 (順位表) の他の問題:

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.

  1. Paint cell $4$, adjacent to cell $3$, red.
  2. Paint cell $5$, adjacent to cell $4$, red.
  3. Paint cell $6$, adjacent to cell $5$, red.
  4. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。