CF1004A.Sonya and Hotels

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.

The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has nn hotels, where the ii-th hotel is located in the city with coordinate xix_i. Sonya is a smart girl, so she does not open two or more hotels in the same city.

Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to dd. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.

Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original nn hotels to the new one is equal to dd.

索尼娅认为,拥有自己的酒店业务是赚钱的最佳方式,因为这样她既能盈利,又可以随意选择休息的地点。

索尼娅所居住的国家是一条无限延伸的直线。这条直线上每个整数坐标处都有一座城市。她目前拥有 nn 家酒店,其中第 ii 家酒店位于坐标为 xix_i 的城市中。索尼娅非常聪明,因此她不会在同一个城市开设两家或更多酒店。

索尼娅意识到,她的业务需要通过开设新酒店来进一步扩展,因此她决定再建造一家酒店。她希望这家新酒店到所有已有酒店的最小距离恰好等于 dd。索尼娅明白,满足该条件的可选位置可能有很多,因此她想知道:有多少个城市的坐标可以作为新建酒店的位置?

由于索尼娅正躺在自己某家酒店的按摩浴缸中放松,她请你帮忙计算:有多少个城市坐标可以用来建造这家新酒店,使得该酒店到原有 nn 家酒店的最小距离恰好为 dd?

输入格式

The first line contains two integers nn and dd (1≤n≤1001\leq n\leq 100, 1≤d≤1091\leq d\leq 10^9) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.

The second line contains nn different integers in strictly increasing order x1,x2,…,xnx_1, x_2, \ldots, x_n (−109≤xi≤109-10^9\leq x_i\leq 10^9) — coordinates of Sonya's hotels.

第一行包含两个整数 nn 和 dd(1≤n≤1001\leq n\leq 100,1≤d≤1091\leq d\leq 10^9)—— 分别表示索尼娅已有的酒店数量以及新酒店到所有已有酒店所需的最小距离。

第二行包含 nn 个严格递增的不同整数 x1,x2,…,xnx_1, x_2, \ldots, x_n(−109≤xi≤109-10^9\leq x_i\leq 10^9)—— 表示索尼娅各酒店的坐标。

输出格式

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to dd.

输出 Sonya 可以新建酒店的城市数量,使得该酒店到所有其他酒店的最小距离恰好等于 dd。

输入输出样例

  • 输入#1

    4 3
    -3 2 9 16

    输出#1

    6
  • 输入#2

    5 2
    4 8 11 18 19

    输出#2

    5

说明/提示

In the first example, there are 66 possible cities where Sonya can build a hotel. These cities have coordinates −6-6, 55, 66, 1212, 1313, and 1919.

In the second example, there are 55 possible cities where Sonya can build a hotel. These cities have coordinates 22, 66, 1313, 1616, and 2121.

在第一个例子中,Sonya 可以建酒店的城市共有 66 个。这些城市的坐标分别为 −6-6、55、66、1212、1313 和 1919。

在第二个例子中,Sonya 可以建酒店的城市共有 55 个。这些城市的坐标分别为 22、66、1313、1616 和 2121。

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

首页