Problem:


Score : 300 points

Problem Statement

In a public bath, there is a shower which emits water for T seconds when the switch is pushed.

If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.

N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.

How long will the shower emit water in total?

Constraints

1 ≤ N ≤ 200,000

1 ≤ T ≤ 10^9

0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9

T and each t_i are integers.

Input

Input is given from Standard Input in the following format:

N T
t_1 t_2 ... t_N

Output

Assume that the shower will emit water for a total of X seconds. Print X.

Sample Input 1

2 4
0 3

Sample Output 1

7

Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

Sample Input 2

2 4
0 5

Sample Output 2

8

One second after the shower stops emission of water triggered by the first person, the switch is pushed again.

Sample Input 3

4 1000000000
0 1000 1000000 1000000000

Sample Output 3

2000000000

Sample Input 4

1 1
0

Sample Output 4

1

Sample Input 5

9 10
0 3 5 7 100 110 200 300 311

Sample Output 5

67



Sample input:
2 4
0 3


Sample output:
7

Submission status: Accepted

Solution code:
n,t=map(int,input().split())

T=list(map(int,input().split()))
cnt=0
for i in range(n-1):
    
    if T[i+1]-T[i]<t:
        cnt+=(T[i+1]-T[i])
    else:
        cnt+=t
        
print(cnt+t)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(i) for i in input().split()]

ans = T
for i in range(0,N-1):
    t_diff = t[i+1] - t[i]
    if t_diff > T:
        ans += T
    else:
        ans += t_diff
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
Time = 0
for i in range(1, N):
    Time += min(t[i] - t[i-1], T)
Time += T
print(Time)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
c = n*t
for i in range(n-1):
    if a[i] + t > a[i+1]:
        c -= a[i] + t - a[i+1]
print(c)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
Tn=list(map(int,input().split()))
Tn.append(float('inf'))
ans=0
now=0
for t in Tn:
    if t-now<T:
        ans+=t-now
    elif t-now>=T:
        ans+=T
    now=t
print(ans)

Submission status: Accepted

Solution code:
n,t = (int(i) for i in input().split())
a = [int(i) for i in input().split()]

time = t
for i in range(1,n):
    if a[i]-a[i-1] < t:
        time += a[i]-a[i-1]
    else:
        time += t
print(time)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
A = list(map(int,input().split()))
res = t
for i in range(n-1):
    if A[i]+t<=A[i+1]:
        res += t
    else:
        res += A[i+1]-A[i]
print(res)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
def solve():
  count = T
  for i in range(1, len(t)):
    d=t[i] - t[i-1]
    if d<T:
      count-=(T-d)
    count+=T
  return count
  
print(solve())

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
tt=list(map(int,input().split()))
X=0
for i in range(1,N):
  sa=tt[i]-tt[i-1]
  if(sa<T):
    X+=sa
  else:
    X+=T
X+=T
print(X)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
L = [int(i) for i in input().split()]
gap=[]
time=T

for i in range(N-1):
	gap.append(L[i+1]-L[i])

for i in range(N-1):
	time += min(gap[i],T)

print(time)

Submission status: Accepted

Solution code:
from functools import reduce; from operator import add; print((lambda T, L: (reduce(add, (lambda t, l: [min(i - j, t) for i, j in zip(l[1:], l[:-1])])(T, L)) + T) if len(L) > 1 else T)(int(input().split()[1]), list(map(int, input().split()))))

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
l.append(l[-1]+t)
s=0
for i in range(len(l)-1):
  s+=min(l[i+1]-l[i],t)
print(s)

Submission status: Accepted

Solution code:
num,time = map(int, raw_input().split())
t = raw_input().split()
ans = time
for i in range(0,num-1):
 	a = int(t[i+1])-int(t[i]) 
	if a < time:
		ans += a
	else:
		ans += time
print ans

Submission status: Accepted

Solution code:
num,time = map(int, raw_input().split())
t = raw_input().split()
ans = time
for i in range(0,num-1):
	if int(t[i+1])-int(t[i]) < time:
		ans += int(t[i+1])-int(t[i])
	else:
		ans += time
print ans

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
t = input().split()
t = [int(i) for i in t]
t_len = len(t)
t_diff = [t[i+1] - t[i] for i in range(t_len-1)]
for i in range(t_len-1):
    if t_diff[i] > T:
        t_diff[i] = T
print(sum(t_diff)+T)

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))
    ans = T
    for i in range(1, N):
        ans += t[i] + T - max(t[i], t[i-1] + T)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i+1]-a[i]>t:
        ans+=t
    else:
        ans+=a[i+1]-a[i]
print(ans+t)

Submission status: Accepted

Solution code:
N, T = map(int,input().split())
t = list(map(int,input().split()))

cnt = T
for i in range(N-1):
  cnt += min(T, t[i+1]-t[i])
print(cnt)

Submission status: Accepted

Solution code:
N, T = map(int, raw_input().split())
x = map(int, raw_input().split())

ans = 0
for i in range(N-1):
  ans += min(T, x[i+1]-x[i])
ans += T
print ans

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
l = list(map(int, input().split()))
total = t
for i in range(len(l)-1):
    if l[i+1] - l[i] >= t:
        total += t
    else:
        total += l[i+1] - l[i]
print(total)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
A = []
for i in range(N-1):
    A.append(T-(t[i+1]-t[i]) if t[i+1]-t[i] < T else 0)
print(N*T - sum(A))

Submission status: Accepted

Solution code:
#ABC060C
N,T=map(int,input().split())
t=list(map(int,input().split()))
now=0
ans=0
for tt in t:
	if now<=tt:
		ans+=T
		now=tt+T
	else:
		ans+=tt+T-now
		now=tt+T
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

a = list(map(int,input().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])
su = 0
for i in range(n-1):
    if b[i] >= k:
        su += k
    else:
        su += b[i]
print(su+k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	N, T = map(int, input().split(" "))
	tmp = input().split(" ")
	timming = [int(s) for s in tmp]
	
	time = 0
	for i, val in enumerate(timming):
		if i == (len(timming)-1):
			break
		interval = timming[i+1] - timming[i]
		if interval >= T:
			time += T
		else:
			time += interval
	
	print(time + T)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))

x = T
for i in range(1, N):
    if t[i] - t[i - 1] < T:
        x += t[i] - t[i - 1]
    else:
        x += T

print(x)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
sum=t
for i in range(n-1):
    if l[i+1]-l[i]<=t:
        sum+=l[i+1]-l[i]
    else:
        sum+=t
print(sum)

Submission status: Accepted

Solution code:
def main():
    _, T = map(int, input().split())
    t = [int(s) for s in input().split()]

    print(solve(t, T))

def solve(t, T):
    s = 0
    for ti, tj in zip(t, t[1:]):
        s += min(T, tj - ti)
    
    s += T
    return s

main()

Submission status: Accepted

Solution code:
n,t=[int(i) for i in input().split()]
time=[int(i) for i in input().split()]
now=time[0]
ans=t
for i in range(1,n):
    if now+t>time[i]:
        ans+=time[i]-now
    else:
        ans+=t
    now=time[i]
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n,T = LI()
ans = 0
t = LI()
for i in range(n-1):
    ans += min(T,t[i+1]-t[i])
ans += T
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
L = list(map(int,input().split()))
cnt = 0
prev = L[0]
for x in L:
    if prev + T > x:
        cnt += x - prev
    else:
        cnt += T
    prev = x
 #   print(cnt)
cnt += T
print(cnt)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

B = []
for i in range(N - 1):
    B.append(A[i + 1] - A[i])
    
ans = T
for i in range(N - 1):
    ans += min(B[i], T)
    
print(ans)

Submission status: Accepted

Solution code:
N, T = list(map(int, input().split()))
push_list = list(map(int, input().split()))


dabaaaaa = 0

for i in range(len(push_list)-1):
    if push_list[i + 1] - push_list[i] < T:
        dabaaaaa += push_list[i + 1] - push_list[i]
    else:
        dabaaaaa += T

    # 最後の人が押した後のT秒も加算

print(dabaaaaa+T)

Submission status: Accepted

Solution code:
ans = 0
N, T = list(map(int, input().split()))
t = list(map(int, input().split()))

for i in range(1, N):
    ans += min(T, t[i]-t[i-1])

print(ans + T)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
li_t = list(map(int, input().split()))

counter = 0

for i in range(len(li_t)):
    if i == (len(li_t) - 1):
        counter += t
    else:
        if li_t[i + 1] - li_t[i] >= t:
            counter += t
        else:
            counter += li_t[i + 1] - li_t[i]


print(counter)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for i in range(1,n):
    ans+=min(t,l[i]-l[i-1])
print(ans+t)

Submission status: Accepted

Solution code:
n, T = map(int, input().split())
t = list(map(int, input().split()))
ans = T
for i in range(1, n):
    ans += min(T, t[i] - t[i - 1])
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
difft = [t[i+1] - t[i] for i in range(N-1)]
total = 0
if N == 1:
    print(T)
    exit()
for d in difft:
    total += min(T, d)
print(total+T)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
x = list(map(int,input().split()))
y = 0
s = 0
for i in range(n):
    if y+t<x[i]:
        s += (x[i]-(y+t))
    y = x[i]
print(t+y-s)

Submission status: Accepted

Solution code:
N, T = map(int,input().split())
A = list(map(int,input().split()))
ans = T
for i in range(N-1):
  ans += min(T, A[i+1] - A[i])
print(ans)

Submission status: Accepted

Solution code:
n , t = map(int, input().split())
l = list(map(int, input().split()))
ans = t*n
for i in range(n-1):
    ans -= max(t-l[i+1]+l[i], 0)
print(ans)

Submission status: Accepted

Solution code:
n,t =map(int,input().split())
time = list(map(int,input().split()))
flag =False
ans = 0
for i in range(1,n):
  if time[i]-time[i-1] <=t:
    ans += time[i]-time[i-1] 
  else: 
    ans +=t
print(ans+t)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
T=list(map(int,input().split()))
ans=t
for i in range(1,n):
    ans+=min(T[i]-T[i-1],t)
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,t=map(int,input().split())
T=list(map(int,input().split()))
ans=t
for i in range(1,n):
    ans+=min(T[i]-T[i-1],t)
print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a,ans=list(map(int,input().split())),0
for s in range(n-1):
  if a[s+1]-a[s]<t:
    ans+=a[s+1]-a[s]
  else:ans+=t
print(ans+t)

Submission status: Accepted

Solution code:
(n,t) = (int(i) for i in input().split())
T = [int(j) for j in input().split()]
if n == 1:
    print(t)
else:
    S = [a-b for a,b in zip(T[1:],T[:-1])]
    U = [u if u <= t else t for u in S]
    print(sum(U)+t)

Submission status: Accepted

Solution code:
n,T,*t=map(int,open(0).read().split());print(T+sum(min(j-i,T)for i,j in zip(t,t[1:])))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
x = list(map(int,input().split()))
s = 0
for i in range(1,a):
    if x[i]-x[i-1] < b:
        s+=x[i]-x[i-1]
    else:
        s+=b

print(s+b)

Submission status: Accepted

Solution code:
def solve(N, T, ts):
    return sum([min(ts[i + 1] - ts[i], T) for i in range(N - 1)]) + T


if __name__ == "__main__":
    N, T = tuple(map(int, input().split(" ")))
    ts = list(map(int, input().split(" ")))
    print(solve(N, T, ts))

Submission status: Accepted

Solution code:
n, T = map(int, input().split())
*s, = map(int, input().split())
ans = T

for i in range(1, n):
    ans += min(s[i]-s[i-1], T)
print(ans)

Submission status: Accepted

Solution code:
n, T = map(int, input().split())
*s, = map(int, input().split())
print(T+sum([min(s[i]-s[i-1], T) for i in range(1, n)]))

Submission status: Accepted

Solution code:
def solve():
    [N, T] = [int(x) for x in input().split()]
    ts = [int(x) for x in input().split()]

    return sum([
        min(T, t2-t1) for t2, t1 in zip(ts[1:], ts[:-1])
    ]) + T


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    [N, T] = [int(x) for x in input().split()]
    ts = [int(x) for x in input().split()]

    import collections
    stack = collections.deque()

    for t in ts:
        if not stack:
            stack.append((t, t+T))
            continue

        last = stack.pop()
        if last[1] >= t:
            stack.append((last[0], t+T))
        else:
            stack.append(last)
            stack.append((t, t+T))

    ans = 0
    for t1, t2 in stack:
        ans += (t2 - t1)

    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
start = 0
prev_t = 0
for i in range(N):
    if t[i] - prev_t > T:
        ans += prev_t + T - start
        start = t[i]
    if i == N - 1:
        ans += t[i] + T - start
    prev_t = t[i]

print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
S = list(map(int, input().split()))
cnt = N * T
for i in range(N-1):
    if S[i] + T > S[i+1]:
        cnt -= S[i] + T - S[i+1]
print(cnt)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
A = [int(i) for i in input().split()]
cnt = 0
for i in range(n - 1):
    cnt += min(A[i + 1] - A[i], t)
cnt += t
print(cnt)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    if t[i+1]-t[i] > T:
        ans += T
    else:
        ans += t[i+1]-t[i]
ans += T
print(ans)

Submission status: Accepted

Solution code:
import sys
N,T = [int(n) for n in input().split()]
t = [int(n) for n in input().split()]
ans = 0
for i in range(N-1):
    if(t[i+1]-t[i] < T):
        ans+=t[i+1]-t[i]
    else:
        ans+=T

ans+=T
print(ans)

Submission status: Accepted

Solution code:
n,t = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
ct = t
for i in range(n-1):
  if a[i+1]-a[i] <= t:
    ct += a[i+1]-a[i]
  else:
    ct += t
print(ct)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
A = list(map(int,input().split()))

ans = 0
for i in range(1,N):
    if A[i] > A[i-1]+T:
        ans += T
    else:
        ans += A[i]-A[i-1]
ans += T

print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
t_sum = 0

if N == 1 :
    print(T)
else :
    for i in range(N) :
        if i == N - 1 :
            t_sum += T
        else :
            if t[i+1] - t[i] < T :
                t_sum += (t[i+1] - t[i])
            else :
                t_sum += T

    print(t_sum)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
T = list(map(int,input().split()))
ans = 0

for i in range(1,n):
    if T[i]-T[i-1]>=t:
        ans += t
    else:
        ans += T[i]-T[i-1]


print(ans+t)

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, sep=" ", end="\n"):
    for item in args:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n, t = getInts()
tl = getInts()
ans = 0
last = 0
last_head = 0
for v in tl:
    if v <= last:
        last += (v + t) - last
    else:
        ans += last - last_head
        last_head = v
        last = last_head + t
ans += last - last_head
print(ans)

Submission status: Accepted

Solution code:
n,T=map(int,input().split())
t=[int(i) for i in input().split()]

ans=0
s=0
for i in range(n):
    if i>0:
        if t[i]-t[i-1]>=T:
            ans+=T
        else:
            ans+=t[i]-t[i-1]
            
print(ans+T)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, T = map(int, input().split())
x = 0
f_t = 0

for t in list(map(int, input().split())):
    if t >= f_t:
        x += T
    else:
        x += (t + T - f_t)
    f_t = t + T
    
print(x)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n-1):
    c+=min(a[i+1]-a[i],t)
c+=t
print(c)

Submission status: Accepted

Solution code:
def abc060_c():
    n, T = map(int, input().split())
    t = list(map(int, input().split()))
    total = 0
    for i in range(n - 1):
        criteria = t[i + 1] - t[i]
        if criteria < T:
            total += criteria
        else:
            total += T
    total += T
    print(total)


abc060_c()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(i) for i in input().split()]

ans = 0
now = 0

for i in range(N):
    if now <= t[i]:
        ans += T
    else:
        ans += t[i] + T -now
    now = t[i] + T

print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(e) for e in input().split()]

prev_t = t[0]
ans = T
for _t in t[1:]:
    delta_t = _t - prev_t
    if delta_t <= T:
        ans += delta_t
    else:
        ans += T
    prev_t = _t
print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
ct=t
for i in range(n-1):
  if l[i+1]-l[i]>=t:ct+=t
  else:ct+=l[i+1]-l[i]
print(ct)

Submission status: Accepted

Solution code:
def main():
    n, t = map(int, input().split())
    ts = list(map(int, input().split()))
    res = t
    for i in range(n - 1):
        res += min(t, ts[i + 1] - ts[i])
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, T = map(int, input().split())
t = list(map(int, input().split()))
x = 0
for i in range(n-1):
	d = t[i+1]-t[i]
	if d < T:
		x += d
	else:
		x += T
print(x+T)

Submission status: Accepted

Solution code:
# encoding: utf-8
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = t[-1] + T
pushed = 0
for i, ti in enumerate(t):
    if ti > pushed + T: ans -= (ti - pushed - T)
    pushed = ti

print(ans)

Submission status: Accepted

Solution code:
N,T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    dif = t[i+1]-t[i]
    if dif>=T:
        ans += T
    else:
        ans += dif
        
ans += T # last one
print(ans)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
c = 0

for i in range(n-1):
    c += min(a[i+1]-a[i],t)
c += t
print(c)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(i) for i in input().split()]

S = T
for i in range(1, N):
    S += min(t[i] - t[i-1], T)

print(S)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(i) for i in input().split()]

S = T
for i in range(1, N):
    if t[i] - t[i-1] >= T:
        S += T
    else:
        S += t[i] - t[i-1]

print(S)

Submission status: Accepted

Solution code:
N, T = map(int, input().strip().split(" "))
ts = list(map(int, input().strip().split(" ")))

res = 0
for i in range(len(ts) - 1):
    diff = ts[i + 1] - ts[i]
    res += min(diff, T)
res += T
print(res)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))

result = T
for i in range(1, N):
    if t[i] - t[i-1] <  T:
        result += (t[i] - t[i-1])
    else:
        result += T

print(result)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
time = list(map(int, input().split()))
total = 0
for i in range(N-1):
  span = time[i+1] - time[i]
  if span >= T:
    total += T
  else:
    total += span
total += T
print(total)

Submission status: Accepted

Solution code:
n,t = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
X = 0

for i in range(n):
    if i == 0:
        u = a[0]
        if n == 1:
            X += t
            break
        else:
            v = a[1]
    if u + t < v:
        X += t
    else:
        X += v - u
    u = v
    if i + 1 < n:
        v = a[i + 1]
    if i == n - 1:
        X += t
print(X)

Submission status: Accepted

Solution code:
n, T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]

count = 0
prevEnd = T
for i in range(1, len(t)):
    # print("prevEnd:{} count:{}".format(prevEnd, count))
    if prevEnd <= t[i]:
        count += T
    else:
        count += t[i] - t[i-1]
    prevEnd = t[i] + T
    # print("prevEnd:{} count:{}\n".format(prevEnd, count))
print(count + T)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=[int(i) for i in input().split()]
ans=[0]*3
for i in l:
    if i>=ans[2]:
        ans[0]+=t
        ans[1]=i
        ans[2]=i+t
    else:
        ans[0]+=i+t-ans[2]
        ans[1]=i
        ans[2]=i+t
print(ans[0])

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = 0
now = 0

for i in range(N):
    if t[i] >= now:
        ans += T
    else:
        ans += t[i] - t[i-1]
    
    now = t[i]+T
    
print(ans)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
T = list(map(int,input().split()))
x = 0

for i in range(1, len(T)):
  if T[i]-T[i-1] < t:
    x += T[i]-T[i-1]
  else:
    x += t

print(x+t)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
span = list(map(int, input().split()))
sum_t = 0
for i in range(n-1):
    if span[i+1] - span[i] >= t:
        sum_t += t
    else:
        sum_t += span[i+1] - span[i]
sum_t += t
print(sum_t)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t_list = list(map(int, input().split()))

X = T
prev_t = 0
for t in t_list:
    if t == 0:
        continue
    if prev_t + T > t:
        X += t - prev_t
    else:
        X += T
    prev_t = t
print(X)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
S=list(map(int,input().split()))
t=0
for i in range(0,N-1):
    if S[i+1]-S[i]<T:
        t+=S[i+1]-S[i]
    if S[i+1]-S[i]>=T:
        t+=T
p=t+T
print(p)

Submission status: Accepted

Solution code:
n,T = map(int,input().split())
t_list = list(map(int,input().split()))
ans  = T
prev = 0

for t in t_list:
    if t-prev < T:
        ans += t-prev
    else:
        ans += T
    prev = t
print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
a=t
for i in range(n-1):
    a+=min(l[i+1]-l[i],t)
print(a)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
Ts = list(map(int,input().split()))

ans = 0
right = 0
for t in Ts:
    if right <= t: ans += T
    else: ans += t + T - right
    right = t + T

print(ans)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))

if len(t) == 1:
    print(T)
    exit()

X = 0
for i in range(1,N):
    if i == N - 1:
        X += T
    if t[i] - t[i-1] >= T:
        X += T
    else:
        X += t[i] - t[i-1]

print(X)

Submission status: Accepted

Solution code:
N , T = map(int,input().split())
t = list(map(int, input().split()))
ans = T
for i in range(N-1):
	if t[i] + T < t[i+1]:
		ans += T
	else:
		ans += t[i+1] - t[i]
print(ans)

Submission status: Accepted

Solution code:
_,t=map(int,input().split())
l=list(map(int,input().split()))
s=0
for i in range(len(l)-1):
  j=l[i+1]-l[i]
  if j<t:s+=j
  else:s+=t
s+=t
print(s)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
tl=list(map(int,input().split()))
s=t
for i in range(1,n):
    s+=min(tl[i]-tl[i-1],t)
print(s)

Submission status: Accepted

Solution code:
(n, t) = list(map(int, input().split()))
a = list(map(int, input().split()))
count = t
for i in range(1, len(a)):
    count -= max(0, t - (a[i] - a[i-1]))
    count += t
print(count)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
ans=t
for i in range(1,n):
    ans+=min(t,a[i]-a[i-1])
print(ans)

Submission status: Accepted

Solution code:
n, T = map(int, input().split())
t = list(map(int, input().split()))
ans = T
for i in range(1, n):
    if t[i]-t[i-1] <= T:
        ans += t[i]-t[i-1]
    else:
        ans += T
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
time_array = list(map(int, input().split()))       
sum_time = 0
for i in range(len(time_array)-1):
    if T > time_array[i+1] - time_array[i]:
        sum_time += time_array[i+1] - time_array[i]
    else:
        sum_time += T

print(sum_time + T)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
res = 0
start = 0
for i in range(N):
    if t[i] - start > T:
        res += T
        start = t[i]
    else:
        res += t[i] - start
        start = t[i]
print(res+T)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N, T = map(int, input().split())
tn = list(map(int, input().split()))

estime = T
for i in range(1,N):
    if tn[i] - tn[i-1] > T:
        estime += T
    else:
        estime += tn[i] - tn[i-1]

print(estime)

Submission status: Accepted

Solution code:
def 解():
    iN ,iT = [int(_) for _ in input().split()]
    aT = [int(_) for _ in input().split()]
    tb = 0
    iAns = 0
    for ti in aT[1:]:
        if ti - tb <= iT:
            iAns += ti -tb
        else:
            iAns += iT
        tb = ti
    iAns += iT
    print(iAns)
解()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
t.append(10000000000)
ans = 0
for i in range(N):
    if t[i] + T <= t[i+1]:
        ans += T
    else:
        ans += t[i+1] - t[i]
print(ans)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
dif = []*n
for i in range(len(a)-1):
    dif.append(a[i+1]-a[i])

stan = [j for j in dif if j >= t]
suf = [k for k in dif if k < t]
print(sum(suf) + (t)*(len(stan)+1))

Submission status: Accepted

Solution code:
n,s=map(int,input().split())
t=list(map(int,input().split()))
ans=t[0]
t_sum=t[0]
for i in range(1,n):
    if t[i-1]+s<t[i]:
        ans +=s
    else:
        ans +=t[i]-t[i-1]
ans +=s
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t_list = list(map(int, input().split()))
i = 0
duration = 0
while i < N -1:
    diff = t_list[i+1] - t_list[i]
    if diff > T:
        duration += diff - T
    i += 1
print(t_list[-1] - duration + T)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))

answer = t[-1] + T
t_end = 0
for ti in t:
    answer -= max(ti - t_end, 0)
    t_end = ti + T
print(answer)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
tn = list(map(int, input().split()))
x = 0

for i in range(n-1):
    if tn[i+1] - tn[i] >= t:
        x += t
    else:
        x += tn[i+1] - tn[i]
print(x + t)

Submission status: Accepted

Solution code:
N,T = map(int, input().split())
t_list = list(map(int, input().split()))

ans = T

for i in range(N-1):
    diff = t_list[i+1] - t_list[i]
    if T >= diff:
        ans += diff
    else:
        ans += T
    
print(ans)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
a = list(map(int,input().split()))
s = t
for i in range(0,n-1):
  s += min(t,a[i+1]-a[i])
print(s)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
Ts = list(map(int, input().split()))

ans = 0

for i in range(N-1):
    t = Ts[i]
    tt = Ts[i + 1]

    if tt <= t + T:
        ans += tt - t
    else:
        ans += T

ans = ans + T

print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
Push = [int(i) for i in input().split()]
Total = T

if N >= 2:
    for i in range(1, N):
        if Push[i] >= Push[i-1] + T:
            Total += T
        else:
            Total += Push[i] - Push[i-1]

print(Total)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
listT=list(map(int, input().split()))

index=1
sum=0
while index < len(listT):
    if listT[index] - listT[index-1]<t:
        sum += listT[index] - listT[index-1]
    else:
        sum+=t
    index+=1
sum+=t

print(sum)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
sa = [t[i+1]-t[i] for i in range(N-1)]

ans = 0
for i in sa:
    ans += min(T, i)
print(ans+T)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
sa = [t[i+1]-t[i] for i in range(N-1)]
hazimari = t[0]
las = t[0]
ans = 0

for i in range(N-1):
    
    if sa[i] <= T:
        las = t[i+1]
        
    else:
        ans += las-hazimari+T
        hazimari = t[i+1]
        las = t[i+1]
        
if hazimari != las:
    ans += las -hazimari+T
else:
    ans += T

print(ans)

Submission status: Accepted

Solution code:
N, T = map( int, input().split())
S = list( map( int, input().split()))
S.append(10**10)
ans = 0
now = 0
for i in range(1,N+1):
    ans += min( S[i] - now, T)
    # if S[i] - now >= T:
    #     ans += T
    # else:
    #     ans += S[i] - now
    now = S[i]
print(ans)