题目描述
Problem Description
ABC Market is the most popular supermarket in the Takahashi Kingdom. The entrance has an automatic door.
This automatic door opens automatically when someone approaches and remains open for $ T $ seconds after that, then closes automatically. If a new person approaches while the door is open, the time for which the door remains open is extended by another $ T $ seconds from the time of the new approach.
Today, a total of $ N $ customers approached the automatic door. The time when the $ i $ -th person approached is $ A_i $ seconds after ABC Market opened.
Calculate the total number of seconds the automatic door was open today.
Input Format
The input is given from the standard input in the following format:
$ N $ $ T $ $ A_1 $ $ A_2 $ : $ A_N $
- The first line contains the integer $N(1\ ≦\ N\ ≦\ 10^5)$ representing the number of people who approached the automatic door today, and the integer $T(1\ ≦\ T\ ≦\ 10^5)$ representing the time the door remains open. These are separated by spaces.
- The next $ N $ lines contain the time $A_i(1\ ≦\ A_i\ ≦\ 10^6)$ when the $ i $ -th person approached the door.
- It is guaranteed that $A_1\ ≦\ A_2\ ≦\ …\ ≦\ A_N$.
Output Format
Output the total number of seconds the door was open in one line. End the output with a newline.
Sample Input and Output
Sample Input #1
5 10
20
100
105
217
314
Sample Output #1
45
Sample Input #2
10 10
1
2
3
4
5
6
7
8
9
10
Sample Output #2
19
Sample Input #3
10 100000
3
31
314
3141
31415
314159
400000
410000
500000
777777
Sample Output #3
517253
Notes/Hints
Partial Points
This problem has partial points.
- If you solve the dataset where $1\ ≦\ T\ ≦\ 100$, you will be awarded $ 50 $ points.
- If you solve the dataset where $1\ ≦\ T\ ≦\ 10^5$, you will be awarded an additional $ 50 $ points, totaling $ 100 $ points.
Sample Explanation 1
The door is open at times $ 20 $ ~ $ 30 $, $ 100 $ ~ $ 115 $, $ 217 $ ~ $ 227 $, and $ 314 $ ~ $ 324 $.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分