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:
# -*- coding: utf-8 -*-
"""
https://abc060.contest.atcoder.jp/tasks/arc073_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(data, T):
    ans = 0
    prev_d = data[0]
    for d in data[1:]:
        diff = d - prev_d
        ans += min(T, diff)
        prev_d = d
    ans += T
    return ans


def main(args):
    N, T = map(int, input().split())
    data = [int(x) for x in input().split()]
    ans = solve(data, T)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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


p = 0
q = 0
total = 0
for x in xs:
    q = max(p, x + t)
    total += (q - max(p, x))
    p = q
print(total)

Submission status: Accepted

Solution code:
tmp = input()
userInps = tmp.split()

tmp = input()
times = tmp.split()

total = 0


def check(i):
	# tmp = int(userInps[0])

	if int(userInps[1]) > int(times[i]) - int(times[i-1]):
		# total += (int(times[i]) - int(times[i-1]))
		n = (int(times[i]) - int(times[i-1]))
		# print(times[i-1])
		# print(times[i-2])
		# print(1)


	else:
		# total += int(userInps[0])
		n = int(userInps[1])
		# print(2)

	# print(n)
	return n	


for x in range(1,int(userInps[0])):
	# print(x)
	total += check(x)



total += int(userInps[1])
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]


def solve():
    n, t = LI()
    T = LI()

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

    print(ans + t)


solve()

Submission status: Accepted

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

    ans = 0
    for i in range(N - 1):
        t1 = ts[i]
        t2 = ts[i + 1]
        ans += min(t2 - t1, T)
    ans += T

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
num = [int(x) for x in input().split()]
val = [int(x) for x in input().split()]
res = 0

res = max(val)+num[1]
for i in range(1, len(val)):
    res -= abs(val[i]-val[i-1])-num[1] if abs(val[i]-val[i-1])-num[1] > 0 else 0

print(res)

Submission status: Accepted

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

i_prev=0
gap=0
for i in t:
	if i-i_prev>T:
		gap+=(i-i_prev)-T
	i_prev=i


print t[-1]+T-gap

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):
    hoge = t[i+1] - t[i]
    ans += (hoge < T) * hoge + (hoge >= T) * T
else:
    print(ans + T)

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):
    ans += min(t[i + 1] - t[i], T)
ans += T
 
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, raw_input().split())    
t = map(int, raw_input().split())   
ans = 0
cur = 0
for i in xrange(N - 1):
    if t[i + 1] - t[i] > T:
        ans += t[i] + T - cur
        cur = t[i + 1]
ans += t[N - 1] + T - cur
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):
    ans += min(t[i + 1] - t[i], T)
ans += T

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(1,N):
    if t[i] - t[i-1] >=T:
        ans += T
    else:
        ans += t[i] - t[i-1]
ans += T

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = T * N

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

Submission status: Accepted

Solution code:
n,t=[int(x) for x in input().split()]
tn=[int(x) for x in input().split()]
ans=t
for i in range(len(tn)-1):
    diff=tn[i+1]-tn[i]
    if diff<=t:
        ans+=diff
    else:
        ans+=t
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(N-1):
  now = t[i+1] - t[i]
  ans += min(now, T)

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())

    t_list = [int(t) for t in input().split()]
    sumv = T
    ti_1 = 0
    for ti in t_list[1:]:
        if ti_1 + T <= ti:
            sumv += T
        else:
            sumv += ti-ti_1
        ti_1 = ti
    print(sumv)


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):
    sa = t[i+1] - t[i]
    if sa < T:
        X += sa
    else:
        X += T

X += T
print(X)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X = 0
N, T = map(int, input().split())

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

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

print(X)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
last, time = 0,-T
for temp in map(int,input().split()):
    if temp - last < T:
        time += T - (temp - last)
    last = temp
print(N*T-time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N, T = map(int, input().split())
    TS = list(map(int, input().split()))

    X = 0
    prev = TS[0]
    for i in range(1, N):
        now = TS[i]
        X += min(now-prev, T)
        prev = now
    X += T

    print(X)

if __name__ == "__main__": main()

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):
 if a[i-1]+T > a[i]:
  ans += a[i] - a[i-1] 
 else:
  ans += T
print (ans)

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):
    if a[i-1]+T > a[i]:
        ans += a[i] - a[i-1] 
    else:
        ans += T

print(ans)

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):
    if a[i-1]+T > a[i]:
        ans += T - (a[i-1] + T -a[i])
    else:
        ans += T

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, T = map(int, input().split())
    t_list = list(map(int, input().split()))
    ans = 0
    n = 0
    for t in t_list:
        if t >= n:
            ans += T
        else:
            ans += T - (n - t)
        n = t + T
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

shower = 0

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

shower += T
print(shower)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np

n, t = map(int, input().split())
tmp = list(map(int, input().split()))
a = np.array(tmp)

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

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#入力部
N,T = map(int,input().split())
t_list = list(map(int,input().split()))
#処理部
T_sum = 0
for i in range(N-1):
    if t_list[i+1]-t_list[i] < T:
        T_sum += t_list[i+1]-t_list[i]
    else:
        T_sum += T
T_sum += T
print(T_sum)

Submission status: Accepted

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

tmp = 0
sum_t = 0

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

print(sum_t + T)

Submission status: Accepted

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

N, T = map(int, raw_input().split())
ans = 0
time = map(int, raw_input().split())

ans = 0
tmp = 0
start = time[0]
end = T
for t in time[1:]:
    if end < t:
        ans = ans + (end - start)
        start = t
        end = T + start
    else:
        end = t + T

end = time[N-1] + T
ans = ans + (end - start)

print ans

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('c1.in')

n, T = map(int, input().split())
t = list(map(int, input().split()))
res = 0
t.append(10 ** 20)
for i in range(n):
    dif = t[i + 1] - t[i]
    if dif > T:
        res += T
    else:
        res += dif
print(res)

Submission status: Accepted

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

prevx = ans = 0
for x in a:
	ans += min(x,prevx+t) - prevx
	prevx = x
ans += t
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num,time = map(int, input().split())
times = [int(n) for n in input().split()]
stop = time
total = 0
for i in range(1,num):
    if times[i]<=stop:
        total += times[i]-times[i-1]
    else:
        total += stop-times[i-1]
    stop = times[i]+time
total += time
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

#-------
# Initialize

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

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

#-------
# Output
print(ans)

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))
N,T=x[0],x[1]
t=list(map(int, input().split()))
oyu=0

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

oyu += T
print(oyu)
quit()

Submission status: Accepted

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

time=0
total=0

for i in t:
    if i < time:
        total += i+T-time
        time = i+T
    else:
        total += T
        time = i+T

print total

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N, T = map(int , input().split())
t = list(map(int, input().split()))
ans = 0
for tmp in range(N):
    if tmp == 0:
        ans += T
    else:
        a = t[tmp] - t[tmp-1]
        if a < T:
            ans -= T-a
        ans += T
print(ans)

Submission status: Accepted

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

t = [int(i) for i in input().split()]

X = 0
mae = 0
for i in t:
    if(i == 0):
        X = T
        continue

    gap = i - mae

    if(gap < T):
        X = X + gap
    else:
        X = X + T

    mae = i

print(X)

Submission status: Accepted

Solution code:
def solve():
  ar = raw_input().split(' ')
  N = int(ar[0])
  T = int(ar[1])
  ar = raw_input().split(' ')
  end = 0
  count = 0
  for i in range(N):
    ti = int(ar[i])
    if(ti < end) : count -= (end-ti)
    end = ti + T
    count += T
  return count

if __name__ == '__main__' :
  print solve()

Submission status: Accepted

Solution code:
N, T = map(int,raw_input().split())
t = map(int,raw_input().split())
result = 0

for i, v in enumerate(t):
    if i == 0: continue
    diff = v - t[i - 1]
    if diff > T:
        result += T
    else:
        result += diff
result += T


print result

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

T = int(input().split(" ")[1])
t = [int(x) for x in input().split(" ")]
t.append(100000000000)

ret = 0

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

print(ret)

Submission status: Accepted

Solution code:
import sys

n, t = [int(x) for x in sys.stdin.readline().split()]
a = [int(x) for x in sys.stdin.readline().split()]
total = t
for i in range(n-1):
	d = a[i+1] - a[i]
	if d <= t:
		total += d
	else:
		total += t
print(total)

Submission status: Accepted

Solution code:
#N,Tの取得
N,T = map(int, input().split())
#秒のリストを取得
tl = list(map(int, input().split()))

bt = 0 #直前のスイッチを押した時間
gt = T #秒数総和
for t in tl[1:]:
    if t - bt > T:
        gt += T #スイッチオフの時はT秒追加
    else:
        gt += t - bt #スイッチがオンのとき、前回からの経過時間を加算
    bt = t

print(str(gt))

Submission status: Accepted

Solution code:
#N,Tの取得
l = list(map(int, input().split()))
N = l[0]
T = l[1]

#秒のリストを取得
tl = list(map(int, input().split()))

bt = 0 #直前のスイッチを押した時間
gt = T #秒数総和
for t in tl[1:]:
    if t - bt > T:
        gt += T #スイッチオフの時はT秒追加
    else:
        gt += t - bt #スイッチがオンのとき、前回からの経過時間を加算
    bt = t
        

print(str(gt))

Submission status: Accepted

Solution code:
#N,Tの取得
l = list(map(int, input().split()))
N = l[0]
T = l[1]

#秒のリストを取得
tl = list(map(int, input().split()))

sw = 0 #スイッチオンオフの管理
bt = 0 #直前のスイッチを押した時間
gt = 0 #秒数総和
for i, t in enumerate(tl):
    if sw == 1 and t - bt > T:
        sw = 0 #全快スイッチを押してからT秒経過していたら、スイッチオフ
    if sw == 0:
        gt += T #スイッチオフの時はT秒追加
    else:
        gt += t - bt  #スイッチがオンのとき、前回からの経過時間を加算
    bt = t
    sw = 1 #スイッチオン。
        

print(str(gt))

Submission status: Accepted

Solution code:
n = input()
tmp_n = n.split(" ")

N = tmp_n[0]
T = tmp_n[1]

num = input()
tmp_num = num.split(" ")

yu_interval = int(T)
yu_fin = int(T)
loss_time = 0

for i in range(int(N)):
    if int(tmp_num[i]) <= yu_fin:
        yu_fin = int(tmp_num[i]) + yu_interval
    elif int(tmp_num[i]) > yu_fin:
        loss_time += int(tmp_num[i])-yu_fin
        yu_fin = int(tmp_num[i]) + yu_interval

print(yu_fin-loss_time)

Submission status: Accepted

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

Submission status: Accepted

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

sum_time = 0
for i in range(1, len(tlist)):
    delta = tlist[i] - tlist[i-1]
    shower = delta if delta <= t else t
    sum_time += shower
sum_time += t
print(sum_time)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())
total = 0
for k in range(0, N - 1):
    if t[k + 1] - t[k] <= T:
        total += t[k + 1] - t[k]
    else:
        total += T
total += T
print total

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

t_ary = input().split()
t_ary = np.array([int(e) for e in t_ary])

diff_ary = t_ary[1:] - t_ary[:-1]

#print(diff_ary < T)
#print(diff_ary)

tf_ary = diff_ary < T

total = 0
for i, flag in enumerate(tf_ary):
    if flag:
        total += diff_ary[i]
    else:
        total += T

total += T

print(total)

Submission status: Accepted

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

t_list = [int(x) for x in input().split()]

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

print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N, T= map(int, input().split())
t=list(map(int, input().split()))
count=0
for j in range (0,N-1):
  count+=min(T,t[j+1]-t[j])
print(count+T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
k=list(map(int,input().split()))

time=b
for i in range(a-1):
    tc=k[i+1]-k[i]
    if tc<b:
        time = time+tc
    else:
        time=time+b
print(time)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ini=map(int,raw_input().split())
a=map(int,raw_input().split())

sum=0

for i in range(ini[0]):
  if a[i]==0:
    pass
  else:
    if a[i]-a[i-1]>=ini[1]:
      sum+=ini[1]
    else:
      sum+= a[i]-a[i-1]

sum+=ini[1]

print sum

Submission status: Accepted

Solution code:
# coding: utf-8 
N,T = [int(i) for i in input().split(" ")]
array = input().split(" ")
ans = 0
fin = 0
for x in array:
    time = int(x)
    if time <= fin:
        ans += (time + T - fin)
    else:
        ans += T
    fin = time + T
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())
    TN = tuple(map(int, input().split()))

    i = 0
    t = 0
    while i < N - 1:
        t += min(TN[i+1] - TN[i], T)
        i += 1

    print(t + T)

main()

Submission status: Accepted

Solution code:
n, T = map(int, input().split())
t = list(map(int, input().split()))
total = T
lastnum = 0
for i in t:
    time = i - lastnum 
    if  T < time:
        total += T
    else:
        total += time
    lastnum = i
    
print(total)

Submission status: Accepted

Solution code:
Tsum = 0

catch = input()
catch = catch.split(" ")
T = int(catch[1])

catch = input()
t = catch.split(" ")

t2 = [0]
for i in range(1, len(t)):
    t2.append(int(t[i]) - int(t[i-1]) )

for i in t2:

    if i < T:
        Tsum +=i

    else:
        Tsum +=T

print(Tsum + T)

Submission status: Accepted

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

a = [int(x) for x in input().split()]
sum = 0

for i in range(1, n):
    #print ('a[' + str(i) + '] = ' + str(a[i]))
    if a[i] - a[i - 1] > t:
        tmp = t
    else:
        tmp = a[i] - a[i - 1]
    #print ('tmp = ' + str(tmp))
    sum += tmp
sum += t
print (sum)

Submission status: Accepted

Solution code:
N, T = input().split(' ')
N = int(N)
T = int(T)
x = [i for i in range(N+1)]
t = input()
cnt = 0
for ti in t.split(' '):
    x[cnt] = int(ti)
    cnt += 1
x[cnt] = -1
ans = 0
prev = -1
for ti in x:
    if ti == -1:
        ans += T
    elif prev != -1:
        if ti-prev > T:
            ans += T
        else:
            ans += ti-prev
    prev = ti
print (ans)

Submission status: Accepted

Solution code:
N, T = input().split(' ')
N = int(N)
T = int(T)
x = [i for i in range(N+1)]
t = input()
cnt = 0
for ti in t.split(' '):
    x[cnt] = int(ti)
    cnt += 1
x[cnt] = -1
ans = 0
prev = -1

for ti in x:
    if ti == -1:
        ans += T
    elif prev == -1:
        prev = ti
    else:
        if ti-prev > T:
            ans += T
        else:
            ans += ti-prev

    prev = ti

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

cost = t

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

Submission status: Accepted

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

# print(n, T, t)

sum = 0

for i in range(1,n):
    interval = t[i] - t[i-1]
    if interval < T:
        sum += interval
    else:
        sum += T

sum += T

print(sum)

Submission status: Accepted

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

def count_time(N,T,t):
    cnt = T
    for i in range(N-1):
        tt =t[i+1]-t[i]        
        if tt <=T:
            cnt += tt
        else:
            cnt += T
    return cnt

print(count_time(N,T,t))

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
l = list(map(int, input().split()))
l.append(10**11)
ans = 0

for i in range(n):
    nex = l[i + 1] - l[i]
    ans += min(nex, t)

print(ans)

Submission status: Accepted

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

w = 0

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

w+=T

print(w)

Submission status: Accepted

Solution code:
NT = list(map(int,input().split()))

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


ans = NT[0]*NT[1]

for i in range(len(t)-1):
    if t[i+1]-t[i]<NT[1]:
        ans -= NT[1]-t[i+1]+t[i]
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

if __name__ == "__main__":
    N, T = map(int, raw_input().split(" "))
    t_list = map(int, raw_input().split(" "))

    total = 0
    for i in range(1, N):
        sub = t_list[i] - t_list[i - 1]

        if sub > T:
            total += T
        else:
            total += sub

    total += T
    print total

Submission status: Accepted

Solution code:
# coding: utf-8

n, t = map(int, raw_input().split())
ti_list = map(int, raw_input().split())
ti = ti_list.pop(0)
total = t

for ti_plus1 in ti_list:
    total += min(ti_plus1-ti, t)
    ti = ti_plus1

print total

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = map(int,raw_input().split())
t = map(int,raw_input().split())
sum = 0
for n in range(N-1):
    if t[n+1] - t[n] > T:
        sum += T
    else:
        sum += t[n+1] - t[n]
print sum+T

Submission status: Accepted

Solution code:
#ABC060C

n,t=map(int,raw_input().split())
l=map(int,raw_input().split())
res=0
for i in xrange(1,n):
 res+=min(t,l[i]-l[i-1])
res+=t
print res

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, T = map(int, input().split())
    ts = list(map(int, input().split()))
    
    
amount =0


    
for index in range(N-1):
    t_sub = ts[index+1]-ts[index]
    amount+=min(t_sub,T)

        
amount +=T

print(amount)

Submission status: Accepted

Solution code:
N, t = map(int, raw_input().split())
n = map(int, raw_input().split())
total = 0
next = t
for i in range(N-1):
	if(next < n[i+1]):
		total += t
		next = n[i+1]+t
	else:
		total += n[i+1]-n[i]
		next = n[i+1]+t
total += t
print(total)

Submission status: Accepted

Solution code:
a, b = map(int, raw_input().split(' '))
c = map(int, raw_input().split(' '))
s = 0

for i in range(len(c) - 1):
	t = b - (c[i + 1] - c[i])
	s += t if t > 0 else 0

print a * b - s

Submission status: Accepted

Solution code:
##N T
#t1 t2 ... tN
N, T = map(int,input().split())
a = list(map(int, input().split()))
b = []
zo  = [0, T]
leng = T
"""
d = set()
for i in range(N):
    d = d | set(range(a[i], a[i] + T))
"""
for i in range(N):
    if  a[i] + T <= zo[1]:
        pass
    elif a[i] <= zo[1] and zo[1] <= a[i] + T:
        leng += a[i] + T - zo[1]
        zo[1] = a[i] + T
    elif zo[1] <= a[i]:
        zo[0] = a[i]
        zo[1] = a[i] + T
        leng += T






print(leng)

Submission status: Accepted

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

X = T

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

print(X)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, T = map(int, input().split())
    ts = map(int, input().split())

    ans = 0
    last = -1
    for t in ts:
        s = t + T - 1
        if t <= last:
            ans -= last - t + 1
        ans += T
        last = max(last, s)

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    NT = input().split()
    N = int(NT[0])
    # print(N)
    T = int(NT[1])
    # print(T)
    t = input().split()
    s = 0
    for k in range(N-1):
        tmp = int(t[k+1]) - int(t[k])
        if tmp > T:
            s += tmp-T
    print( int(t[N-1]) + T - s )

Submission status: Accepted

Solution code:
data = input().split()
N = int(data[0])
T = int(data[1])

data = input().split()
t = []
for i in range(N):
	t.append(int(data[i]))

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

print(X)

Submission status: Accepted

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

def check(N,T,t):
    counter=0
    for i in range(N-1):
        finish=t[i]+T
        start=t[i+1]
        #print(counter)        
        if finish>start:
            counter=counter+finish-start
                 
    return counter
print(N*T-check(N,T,t))

Submission status: Accepted

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

while i <= N-2:
	if t[i+1] - t[i] >= T:
		X += T
		i += 1
	else:
		X += t[i+1] - t[i]
		i += 1

X += T

print(X)

Submission status: Accepted

Solution code:
def sentou(NT, ts):
    N, T = map(int, NT.split())
    before_oshitano = None
    total_s = 0
    for t in map(int, ts.split()):
        if before_oshitano is None:
            before_oshitano = t
            continue
        elif T > (t - before_oshitano):
            total_s += t - before_oshitano
        else:
            total_s += T
        before_oshitano = t
    total_s += T

    print(total_s)


# sentou("9 10", "0 3 5 7 100 110 200 300 311")
sentou(input(), input())

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        n, t = map(lambda x: int(x), line.split(" ", 2))
        showers = map(lambda x: int(x), raw_input().split(" "))

        water = 0
        stop = 0
        for shower in showers:
            if stop > shower:
                water -= (stop - shower)
            water += t
            stop = shower + t
        print(water)

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

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

total_emp_T = 0
ts = T
for t in list_t[1:]:
    if t > ts:
        total_emp_T += t - ts
    ts = t + T
ans = ts  - total_emp_T
print(ans)

Submission status: Accepted

Solution code:
### C - Sentou
n,t = [ int(i) for i in input().split() ]
tk = [ int(i) for i in input().split() ]

x=0;
for i in range(n):
    if i == n-1:
        x += t
    else:
        x += min(t, tk[i+1] - tk[i])

print(x)