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

Solution (Python):




N,T = map(int,raw_input().split(" "))
t = map(int,raw_input().split(" "))
X = 0
sum = 0

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

	X = X + T

	print X

Solution (Python):


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
T=int(hyo[1])

mozir=input()
hyo=mozir.split(' ')
t=[ int(mono) for mono in hyo]

X=0

hazimetime=None
owaritime=None
for hito in t:
    
    if owaritime != None:
        if owaritime > hito:
            X=X+(hito-hazimetime)
        else:
            X=X+T
        
    
    hazimetime=hito
    owaritime=hito+T



X=X+T
print(X)

Solution (Python):
import sys

N, T = sys.stdin.readline().rstrip().split()
t_list = sys.stdin.readline().rstrip().split()

N = int(N)
T = int(T)
t_list = [int(x) for x in t_list]

t_old = t_list[0]
t_sum = T
for t in t_list:
    t_diff = t - t_old

    if t_diff >= T:
        t_sum += T
    else:
        t_sum += t_diff

    t_old = t

print(t_sum)

Solution (Python):
N, T = list(map(int, input().split()))
t =  list(map(int, input().split()))
ans = N*T
t.pop(0)   
for i in range(len(t)):
    if i == len(t) - 1:
        break
    t[len(t) - 1- i] -= t[len(t) - 2 - i]
for i in t:
    if i < T:
        ans -= T - i
print(ans)

Solution (Python):
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())

X = T

dur = T



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

print(X)

Solution (Python):
f=map(int, raw_input().split())
s=map(int, raw_input().split())

total=0

for i in range(1,f[0]):
    total+=min(f[1], s[i]-s[i-1])

total+=f[1]

print total

Solution (Python):

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


X = 0

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

X = X + T 
print(X)

Solution (Python):




import numpy as np
import itertools

N, T = map(int, raw_input().split())
Timings = map(int, raw_input().split())

TotalTime = 0
beforeTime = 0
for i in range(N):
    if (Timings[i] - beforeTime) > T or i == 0:
        TotalTime += T
    else:
        TotalTime += Timings[i] - beforeTime
    beforeTime = Timings[i]

print TotalTime

Solution (Python):
N, T = map(int, input().split())

pushed_time = list(map(int, input().split()))
period = [pushed_time[0], pushed_time[0] + T]

duration = 0

for t_i in pushed_time[1:]:
    if t_i <= period[1]: 
        period[1] = t_i + T 
    else:
        duration += period[1] - period[0]
        
        period = [t_i, t_i + T] 
duration += period[1] - period[0]

print(duration)

Solution (Python):

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


ret = T

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

print(ret)

Solution (Python):

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

diffs=0
for i in range(1,N):
    diff = t[i] - t[i-1]
    if diff < T:
        diffs = diffs + T - diff

print(T*N-diffs)

Solution (Python):


def solve():
    timer = 0
    count = 0
    ans = 0
    while (count < n):
        diff = timer - ti[count]
        timer = ti[count] + t
        if 0 < (diff) < t:
            ans += t - diff
        else:
            ans += t
        count += 1
    print(ans)

if __name__ == '__main__':
    n, t = map(int, input().split())
    ti = list(map(int, input().split()))
    solve()

Solution (Python):


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

Solution (Python):
N, T = map(int, raw_input().split())
TL = map(int, raw_input().split())

e = 0
ans = 0
for t in TL:
    ans += min(t + T - e, T)
    e = T + t
print ans

Solution (Python):
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())

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

Solution (Python):
N,T = map(int,input().split())
tau = list(map(int,input().split()))
answer = 0
cont = 0
for i in range(N):
	if tau[i] < cont:
		dif = cont - tau[i]
		answer += T - dif
	else:
		answer += T
	cont =tau[i] + T
print(answer)

Solution (Python):
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())

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

Solution (Python):
import sys
import math

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())
def nil(): return list(map(int, stdin.readline().split()))

N, T = nil()

t = nil()

s = 0

for i in range(0, len(t)-1):
    f = T - (t[i+1] - t[i])
    if f > 0:
        s += f

print(N*T - s)

Solution (Python):
N,T = map(int,input().split())
times = list(map(int,input().split()))
ans = T
t1 = 0
for t2 in times:
	t = t2 - t1
	t1 = t2
	ans = ans + min(t, T)
print(ans)

Solution (Python):
N,T=list(map(int, input().split()))
t=[0]*N
t=list(map(int, input().split()))

S=T

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

print(S)

Solution (Python):
NT = list(map(int, input().split()))
N = NT[0]
T = NT[1]
del NT

t = list(map(int, input().split()))

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

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

sum = 0
start = t[0]
end = t[0] + T

for i in range(N - 1):
    if end >= t[i + 1]:
        sum += t[i + 1] - start
        start = t[i + 1]
        end = t[i + 1] + T
    else:
        sum += end -start
        start = t[i + 1]
        end = t[i + 1] + T

sum += end - start

print(sum)

Solution (Python):
n,t=map(int,input().split())
hito=list(map(int,input().split()))
ans=n*t
for i in range(len(hito)-1):
    if hito[i+1]-hito[i]<t:
        ans-=t-(hito[i+1]-hito[i])
print(ans)

Solution (Python):
N, T = map(int, input().split())
ti = input().split()

sum = T
for i in range(1, N):
    if (int(ti[i]) - int(ti[i-1])) <= T:
        sum += (int(ti[i]) - int(ti[i-1]))
    else:
        sum += T

print(sum)

Solution (Python):

import numpy as np

if __name__ == "__main__":
	n, t = map(int, input().split())
	tn = list(map(int, input().split()))

	clusters = [[0, 0]]
	for i in range(0, len(tn)-1):
		if tn[i+1] - tn[i] <= t:
			clusters[-1][1] = i+1
		else:
			clusters.append([i+1, i+1])

	tsum = 0
	for s, e in clusters:
		tsum += tn[e] - tn[s] + t

	print(tsum)

Solution (Python):

N,T=map(int,raw_input().split(' '))
t=map(int,raw_input().split(' '))

X=0

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

print X

Solution (Python):
N, T = [int(x) for x in input().split()]
t = [int(x) for x 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)

Solution (Python):
n, T = map(int,raw_input().split())
t = map(int,raw_input().split())
mt = 0
for i in range(1, n):
    if t[i] - t[i - 1] > T:
        mt += t[i] - t[i - 1] - T
print t[n-1] + T - mt

Solution (Python):
def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

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

    print(total)


if __name__ == "__main__":
    main()

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

sum_time += T

print(sum_time)

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

Solution (Python):

N,T = map(int,input().split())
t = input()

t = t.split()
for i in range(len(t)):
    t[i] = int(t[i])

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

Solution (Python):
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
C = A[1]
for i in range(A[0]-1):
    ii = i + 1
    if B[ii] - B[i] < A[1]:
        C = C + B[ii] - B[i]
    else:
        C = C +A[1]
print(C)

Solution (Python):
N, T = map(int, input().split())
tn = map(int, input().split())

prev = 0
ans = 0
for t in tn:
    ans += min(T, t - prev + T)
    prev = t + T
    
print(ans)

Solution (Python):
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)

Solution (Python):
def rren(): return list(map(int, input().split()))

N, oyu = rren()
T = rren()

Ans = 0
for i in range(N-1):
    Ans += oyu if T[i+1] - T[i] >= oyu else T[i+1] - T[i]

print(Ans + oyu)