CF1185A.Ropewalkers

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.

The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions aa, bb and cc respectively. At the end of the performance, the distance between each pair of ropewalkers was at least dd.

Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by 11 (i. e. shift by 11 to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".

You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to dd.

Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.

波利卡普决定在周末放松一下,去观看著名绳索行走者阿加丰、博纳法斯和康拉德的表演。

绳索是笔直且向两侧无限延伸的。在表演开始时,阿加丰、博纳法斯和康拉德分别位于位置 aa、bb 和 cc。在表演结束时,每对绳索行走者之间的距离至少为 dd。

绳索行走者可以在绳索上行走。每一秒,仅允许一名绳索行走者改变其位置。每位绳索行走者每次恰好移动 11 单位(即在绳索上向左或向右移动 11 个单位)。阿加丰、博纳法斯和康拉德不能同时移动(即每一时刻仅有一人可以移动)。绳索行走者可以同时处于同一位置,也可以“彼此穿过”。

你需要求出该表演的最短持续时间(以秒为单位)。换言之,求出使得每对绳索行走者之间的距离均大于等于 dd 所需的最少秒数。

由于绳索向两侧无限延伸,绳索行走者可以走到负坐标位置。

输入格式

The only line of the input contains four integers aa, bb, cc, dd (1≤a,b,c,d≤1091 \le a, b, c, d \le 10^9). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.

输入仅包含一行,其中有四个整数 aa、bb、cc、dd(1≤a,b,c,d≤1091 \le a, b, c, d \le 10^9)。在表演开始时,任意两名(或全部三名)绳舞者可能位于同一位置。

输出格式

Output one integer — the minimum duration (in seconds) of the performance.

输出一个整数——表演的最短持续时间(单位:秒)。

输入输出样例

  • 输入#1

    5 2 6 3

    输出#1

    2
  • 输入#2

    3 1 5 6

    输出#2

    8
  • 输入#3

    8 3 3 2

    输出#3

    2
  • 输入#4

    2 3 10 4

    输出#4

    3

说明/提示

In the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position 88), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be ∣5−2∣=3|5 - 2| = 3, the distance between Boniface and Konrad will be ∣2−8∣=6|2 - 8| = 6 and the distance between Agafon and Konrad will be ∣5−8∣=3|5 - 8| = 3. Therefore, all three pairwise distances will be at least d=3d=3, so the performance could be finished within 2 seconds.

在第一个例子中:前两秒内,康拉德向右移动了 2 个位置(到达位置 88),而阿加丰和博尼法斯则停留在原地。因此,阿加丰与博尼法斯之间的距离为 ∣5−2∣=3|5 - 2| = 3,博尼法斯与康拉德之间的距离为 ∣2−8∣=6|2 - 8| = 6,阿加丰与康拉德之间的距离为 ∣5−8∣=3|5 - 8| = 3。于是,全部三组两两距离均不小于 d=3d=3,故该表演可在 2 秒内完成。

输入解题思路,AI测评打分。不知道怎么写?

首页