問題一覧 > 通常問題

No.126 Two Elevators

レベル : / AI推定難易度 : 800 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 233
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 219 / 自分の提出
問題文最終更新日: 2026-06-25 03:44:17
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. Back to the original
yukicoder contest 76 (順位表) の他の問題:

Problem Statement

Wilson has come to a shopping center.
The shopping center has 100 floors above ground and 1 basement floor, for a total of 101 floors.
The shopping center has 2 elevators side by side (call them elevator $A$ and elevator $B$).
However, only elevator $A$ can go to the first basement floor.
(Elevator $B$ cannot go to the first basement floor.)

Each floor has up and down buttons. When either button is pressed, the car of the elevator closer to that floor moves there and opens its doors to let the customer on.
If both are at the same distance, elevator $A$ takes priority.
If an elevator is already on that floor, neither elevator moves and the doors simply open.
However, when the down button is pressed on the 1st floor, elevator $B$ cannot make that move, so only elevator $A$ comes and opens its doors.
(Even if elevator $B$ is already on the 1st floor, elevator $A$ comes.)

Inside an elevator car, you can press the button of any floor that elevator can reach and travel there.

Wilson wants to get to the first basement floor using only these elevators.
The initial position of each elevator can be known.

Given the current positions of the elevators (floors $A$ and $B$) and Wilson's position (floor $S$), find the minimum total number of floor-to-floor moves made by the elevators.
Moves made without a customer on board are also counted, and assume there are no other customers.
(In the given values, the first basement floor is represented by $0$.)
It is not possible to do things like getting on an elevator, pressing a button inside, and immediately getting off.


(Side note: This is modeled on an actual facility.)

Input

$A$ $B$ $S$

All inputs are given as integers.
$0 \le A \le 100=10^2$
$1 \le B \le 100=10^2$
$1 \le S \le 100=10^2$

Output

Output the minimum number of floor-to-floor moves made by the elevators.
Print a newline at the end.

Sample

Sample 1
Input
5 10 7
Output
9

Wilson starts on floor $7$. When the down button is pressed, since $7-5<10-7$, elevator A comes to floor $7$ (number of moves: $2$), then heads for the first basement floor (number of moves: $7$).
Therefore, the total number of moves is 9.

Sample 2
Input
10 50 30
Output
50

Both elevators need $20$ moves to reach the current floor, so elevator $A$ heads there.
It first goes up to floor $30$, then moves to the first basement floor.

Sample 3
Input
0 1 1
Output
2

Elevator $A$ is already on the first basement floor, but the elevator must first move to floor $1$.
Note that when the down button is pressed on floor $1$, elevator $A$ moves.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。