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 2
4 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<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{ int n,d;
cin>>n>>d;
int a[105];
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
}
sort(a,a+n);
long long int sum=2;
for(int t=0;t<n-1;t++)
{
if(a[t]+d<=a[t+1]-d)
{
if((a[t+1]-a[t]-2*d+1)>2)
sum+=2;
else
sum+=a[t+1]-a[t]-2*d+1;
}
}
cout<<sum<<endl; return 0;
}

CodeForces - 1004A-Sonya and Hotels(思维)的更多相关文章

  1. [Codeforces Round495A] Sonya and Hotels

    [题目链接] https://codeforces.com/contest/1004/problem/A [算法] 直接按题意模拟即可 时间复杂度 :O(NlogN) [代码] #include< ...

  2. codeforces C. Sonya and Problem Wihtout a Legend(dp or 思维)

    题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i ...

  3. Codeforces 714C. Sonya and Queries Tire树

    C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...

  4. Codeforces 713A. Sonya and Queries

    题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类 ...

  5. CodeForces - 427A (警察和罪犯 思维题)

    Police Recruits Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  6. Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  7. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

  8. codeforces 893D Credit Card 贪心 思维

    codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...

  9. CodeForces 1151F Sonya and Informatics

    题目链接:http://codeforces.com/problemset/problem/1151/F 题目大意: 给定长度为 n 的 01 序列,可以对该序列操作 k 次,每次操作可以交换序列中任 ...

  10. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. URL过滤

    URL过滤 就是网址过滤.把不安全的.少儿不宜的.政治的东西过滤掉,访问这些网址就会提示受限,不能访问. 一.url过滤简介 针对企业对员工上网行为的控制管理,可以采用URL过滤技术.如企业不允许研发 ...

  2. ctypes模块与pywin32模块

    ctypes模块: 主要用于调用c动态链接库. 1.聊聊Python ctypes模块 2.ctypes模块管理 相关网址: pywin32模块: 用于访问win32API函数(win32api模块) ...

  3. python 列表之队列

    列表实现队列操作(FIFO),可以使用标准库里的 collections.deque,deque是double-ended quene的缩写,双端队列的意思,它可以实现从队列头部快速增加和取出对象. ...

  4. [acm]HDOJ 3082 Simplify The Circuit

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3082 字符串处理+并联电阻公式 //11481261 2014-08-18 16:52:47 Acc ...

  5. MySQL_各城市在线产品天订单数据20161130

    #sealreport010 `tb010_02d`各城市在线产品天订单数据 #sealreport010 `tb010_02d`各城市在线产品天订单数据 SELECT d.ID,a.城市,a.在线日 ...

  6. ACM学习历程——POJ1260 Pearls(动态规划)

    Description In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces ...

  7. codevs 1144 守望者的逃离

    传送门 1144 守望者的逃离 2007年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 恶 ...

  8. bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 关于置换群:https://www.cnblogs.com/nietzsche-oie ...

  9. 查看SELinux状态&关闭SELinux

    1. 查看SELinux状态 1.1 getenforce getenforce 命令是单词get(获取)和enforce(执行)连写,可查看selinux状态,与setenforce命令相反. se ...

  10. 信息安全:Token

    ylbtech-信息安全:Token Token(计算机术语) 在计算机身份认证中是令牌(临时)的意思,在词法分析中是标记的意思. 1.令牌返回顶部 1.令牌 (信息安全术语) Token, 令牌,代 ...