欧姆龙编程竞赛 2026(第 479 场 AtCoder Beginner Contest)
狭窄通道AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There are $N$ people standing on a number line. The people are numbered $1, 2, \ldots, N$, and initially person $i$ is at coordinate $S_i$. Here, the $S_i$ are pairwise distinct.
数轴上站着 $N$ 个人。这些人的编号为 $1, 2, \ldots, N$,初始时,第 $i$ 个人位于坐标 $S_i$。其中,$S_i$ 两两不同。AI (CI翻译)
You can repeatedly perform the following operation.
你可以重复执行以下操作。AI (CI翻译)
- Choose one person. Let
$x$be the coordinate where that person currently is, and move them to$x - 1$or$x + 1$. If there is a person at the destination, that person is simultaneously moved to coordinate$x$.
- 选择一个人。设这个人当前所在的坐标为
$x$,将其移动到$x - 1$或$x + 1$。如果目标位置已经有人,则那个人会同时被移动到坐标$x$。
Find the minimum number of operations required to reach a state where each person $i$ is at coordinate $T_i$. Here, the $T_i$ are pairwise distinct.
求使每个人 $i$ 都位于坐标 $T_i$ 所需的最少操作次数。其中,$T_i$ 两两不同。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq N \leq 2 \times 10^5$$0 \leq S_i, T_i \leq 10^9$$S_i \neq S_j$and$T_i \neq T_j$if$i \neq j$.- All input values are integers.
$1 \leq N \leq 2 \times 10^5$$0 \leq S_i, T_i \leq 10^9$- 当
$i \neq j$时,$S_i \neq S_j$且$T_i \neq T_j$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入通过标准输入以如下格式给出:AI (CI翻译)
N
S_1 S_2 \ldots S_N
T_1 T_2 \ldots T_N
N
S_1 S_2 \ldots S_N
T_1 T_2 \ldots T_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer.
输出答案。AI (CI翻译)
样例
Input #1
3
4 2 5
3 4 1
Output #1
6
Initially, persons $1, 2, 3$ are at coordinates $4, 2, 5$, respectively. By performing the operations as follows, persons $1, 2, 3$ end up at coordinates $3, 4, 1$, respectively, in six operations.
- Move person $1$ from coordinate $4$ to $3$. After this operation, persons $1, 2, 3$ are at coordinates $3, 2, 5$, respectively.
- Move person $1$ from coordinate $3$ to $2$. Since person $2$ is at coordinate $2$, person $2$ simultaneously moves to coordinate $3$. After this operation, persons $1, 2, 3$ are at coordinates $2, 3, 5$, respectively.
- Move person $3$ from coordinate $5$ to $4$. After this operation, persons $1, 2, 3$ are at coordinates $2, 3, 4$, respectively.
- Move person $3$ from coordinate $4$ to $3$. Since person $2$ is at coordinate $3$, person $2$ simultaneously moves to coordinate $4$. After this operation, persons $1, 2, 3$ are at coordinates $2, 4, 3$, respectively.
- Move person $3$ from coordinate $3$ to $2$. Since person $1$ is at coordinate $2$, person $1$ simultaneously moves to coordinate $3$. After this operation, persons $1, 2, 3$ are at coordinates $3, 4, 2$, respectively.
- Move person $3$ from coordinate $2$ to $1$. After this operation, persons $1, 2, 3$ are at coordinates $3, 4, 1$, respectively.
Input #2
4
2 4 5 9
2 4 5 1
Output #2
11
Input #3
6
5 2 9 1 6 8
1 4 7 0 9 3
Output #3
13
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。