#abc270b. B - Hammer

B - Hammer

Score : 200200 points

问题描述

高桥位于数轴的原点处。他想要到达坐标为 XX 的目标位置。

在坐标为 YY 的位置有一堵墙,起初高桥无法越过这堵墙。
然而,在获取了坐标为 ZZ 的一把锤子后,他可以摧毁这堵墙并穿过。

判断高桥是否能够到达目标位置。如果可以,计算出他需要行走的最小总距离。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi is at the origin of a number line. He wants to reach a goal at coordinate XX.

There is a wall at coordinate YY, which Takahashi cannot go beyond at first.
However, after picking up a hammer at coordinate ZZ, he can destroy that wall and pass through.

Determine whether Takahashi can reach the goal. If he can, find the minimum total distance he needs to travel to do so.

Constraints

  • 1000X,Y,Z1000-1000 \leq X,Y,Z \leq 1000
  • XX, YY, and ZZ are distinct, and none of them is 00.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

XX YY ZZ

Output

If Takahashi can reach the goal, print the minimum total distance he needs to travel to do so. If he cannot, print -1 instead.

Sample Input 1

10 -10 1

Sample Output 1

10

Takahashi can go straight to the goal.

Sample Input 2

20 10 -10

Sample Output 2

40

The goal is beyond the wall. He can get there by first picking up the hammer and then destroying the wall.

Sample Input 3

100 1 1000

Sample Output 3

-1

update @ 2024/3/10 11:22:52