博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 1004A-Sonya and Hotels(思维)
阅读量:5062 次
发布时间:2019-06-12

本文共 2258 字,大约阅读时间需要 7 分钟。

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 xixi. 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.

Input

The first line contains two integers nn and dd (1≤n≤1001≤n≤100, 1≤d≤1091≤d≤109) — 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,…,xnx1,x2,…,xn (−109≤xi≤109−109≤xi≤109) — coordinates of Sonya's hotels.

Output

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.

Examples

Input

4 3-3 2 9 16

Output

6

Input

5 24 8 11 18 19

Output

5

Note

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.

题解:

判断是否有交叉,如果有就不加,没有就加差值,但是差值最大只能是2,超过2的当2算

#include
#include
#include
#include
using namespace std;int main(){ int n,d; cin>>n>>d; int a[105]; for(int t=0;t
2) sum+=2; else sum+=a[t+1]-a[t]-2*d+1; } } cout<
<

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781910.html

你可能感兴趣的文章
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>
配置链路聚合中极小错误——失之毫厘谬以千里
查看>>
代码整洁
查看>>
蓝桥杯-分小组-java
查看>>
Android Toast
查看>>
iOS开发UI篇—Quartz2D使用(绘制基本图形)
查看>>
docker固定IP地址重启不变
查看>>
桌面图标修复||桌面图标不正常
查看>>
JavaScript基础(四)关于对象及JSON
查看>>
JAVA面试常见问题之Redis篇
查看>>
jdk1.8 api 下载
查看>>
getElement的几中属性介绍
查看>>
HTML列表,表格与媒体元素
查看>>
PHP、Java、Python、C、C++ 这几种编程语言都各有什么特点或优点?
查看>>
雨林木风 GHOST_XP SP3 快速装机版YN12.08
查看>>
java对象的深浅克隆
查看>>
数据结构3——浅谈zkw线段树
查看>>
Introduction to my galaxy engine 2: Depth of field
查看>>
Python 3.X 练习集100题 05
查看>>