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):
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]


def calc(T, t):
        acc = 0
        start = 0
        end = 0
        for i in range(len(t)):
                s = t[i]
                if s >= end:
                        acc += end - start
                        start = s
                end = s + T
        acc += end - start
        print acc

N, T = rdi()
t = rdi()
calc(T, t)

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

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



Tlist.reverse()
goukei = 0
tugi_time = 1e10
for t_i in Tlist:
	goukei += min( T , tugi_time - t_i )
	tugi_time = t_i

print (goukei)

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

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

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

rest = 0
ans = 0
prev = 0
for i in xrange(n):
    ti = T[i]
    if rest > 0:
        ans += min(rest, ti - prev)
        rest = max(0, rest - (ti - prev))
    rest = t
    prev = T[i]
print ans + rest

Solution (Python):
n, T = [int(_) for _ in raw_input().split()]
s = 0
S = 0
x = 0
for t in [int(_) for _ in raw_input().split()]:
    e = s + T
    if e < t:
        x += e - S
        S = t
    s = t

x += t + T - S

print(x)

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

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

a = 0

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

a += T

print(a)

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

ans = sum([min(ts[i + 1] - ts[i], T) for i in range(N - 1)]) + T
print(ans)

Solution (Python):

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

res = 0

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

print(res)

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

dift = [t[i]-t[i-1] for i in range(1,n)]
ret = [min(dift_,T) for dift_ in dift]

print(sum(ret)+T)

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,t = LI()
    a = LI()
    s = 0
    c = 0
    r = 0
    for b in a:
        if c < b:
            r += c - s
            s = b
            c = b+t
        else:
            c = b+t
    r += c-s

    return r


print(main())

Solution (Python):
PROBLEM = "A"
FILE = "%s" %(PROBLEM) 
INF = 999999999999999999L
try:
    inFile = open(FILE+".txt")
except:
    inFile = None

def read():
    if inFile:
        return inFile.readline().strip()
    else:
        return raw_input().strip()

def read_ints():
    return map(int,read().split())

n,T = read_ints()
times = read_ints()
ans = 0

for i in xrange(len(times)-1):
    ans += min(T,times[i+1]-times[i])
ans += T
print ans

Solution (Python):
N, T = map(int, input().split())
t = [int(x) for x in input().split()]
print(N * T - sum(max(0, T - (t[i+1] - t[i])) for i in range(N - 1)))

Solution (Python):
import sys

def solve():
    N, T = map(int, input().split())
    ts = [int(i) for i in input().split()]

    cur = ts[0]
    ans = 0

    for ti in ts[1:]:
        ans += min(T, ti - cur)
        cur = ti

    ans += T

    print(ans)


if __name__ == '__main__':
    solve()

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

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

ans += T

print ans