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:
# ABC60 C - Sentou
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i != N-1:
        ans += min(T, t[i+1]-t[i])
    else:
        ans += T
print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N,T = map(int,input().split())
    t = list(map(int,input().split()))
    
    push,time,ans = 0,T,0
    for i in range(N):
        if t[i] <= time:
            time = t[i] + T
        else:
            ans += (time-t[push])
            push = i
            time = t[i]+T
        
    ans += (time - t[push])
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    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)
    print(ans+t)
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]-A[i-1] >= t:
    ans += t
  else:
    ans += A[i] - A[i-1]
print(ans)

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

Submission status: Accepted

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


dp = [0] * N
dp[0] = T

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

print(dp[-1])

Submission status: Accepted

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

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 = map(int, input().split())

time_lis = [int(_) for _ in input().split()]
length = len(time_lis)

ans = 0
for n in range(1, length):
    diff = time_lis[n] - time_lis[n - 1]
    if diff >= T:
        ans += T
    else:
        ans += diff
print(ans + T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N, T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
ans = 0
t = np.array(t)
t_diff = np.diff(t)
for i in t_diff:
    ans += min(i, T)
print(ans + T)

Submission status: Accepted

Solution code:
N, T = list(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:
a,b = [int(i) for i in input().split()]
 
l = [int(i) for i in input().split()]
ans = 0
for i in range(1,a):
    if l[i] - l[i -1] > b:
        ans += b
    else:
        ans += l[i] - l[i-1]
        
ans += b
 
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#060 C Sentou
import sys
N, T = map(int, sys.stdin.readline().split())
L = list(map(int, sys.stdin.readline().split()))
E = [0 for _ in range(N)]
#print(L)
total=0
for i in range(N):
    E[i] = L[i]+T
    total +=E[i] - max(E[i-1], L[i])

if N==1:
    total=T
print(total)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
a = 0
c = -T
for ti in map(int, input().split()):
  a += min(T, ti - c)
  c = ti
print(a)

Submission status: Accepted

Solution code:
import sys

n, T, *t = map(int, sys.stdin.read().split())

def main():
    start = 0
    will_stop = T
    running_time = 0
    for i in range(1, n):
        cur = t[i]
        if cur < will_stop:
            running_time += cur - start
        else:
            running_time += T
        start = cur
        will_stop = cur + T
    running_time += T

    return running_time

if __name__ == '__main__':
    ans = main()
    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):
    ans += min(T, t[i + 1] - t[i])
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):
    if t[i] + T <= t[i + 1]:
        ans += T
    else:
        ans += t[i + 1] - t[i]
ans += T
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

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

sum = 0
end = 0
for i in range(N):
    if end <= ts[i]:
        sum += T
    else:
        sum += T - (end - ts[i])
    end = ts[i] + T
print(sum)

Submission status: Accepted

Solution code:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, T = MAP()
A = MAP()

ans = 0
end = 0
for a in A:
	if end > a:
		ans += T - (end-a)
	else:
		ans += T
	end = a+T
print(ans)

Submission status: Accepted

Solution code:
#60c
N,T = map(int, input().split())
t_list = [int(e) for e in input().split()]

ans = 0

start_time = 0
extend_start_time = 0

for i in range(N):
    #print(t_list[i])
    
    if t_list[i] - extend_start_time <= T:
        extend_start_time = t_list[i]
        #print("extended")
    else:
        ans += T + extend_start_time - start_time
        #print(extend_start_time,start_time)
        #print("ans += ",T +  extend_start_time - start_time)
        start_time = t_list[i]
        extend_start_time = t_list[i]

ans += T + extend_start_time - start_time
        
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
lst = list(map(int,input().split()))
ma = lst[-1] + T
for i in range(len(lst)-1):
  sub = lst[i+1] - lst[i]
  if (sub > T):
    ma -= lst[i+1] - T - lst[i]
print(ma)

Submission status: Accepted

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

res = 0
pre_t = 0
for i in range(N):
    cur_t = t[i]

    if i==0:
        res+=T
    elif cur_t - pre_t >= T:
        res += T
    else:
        res += cur_t - pre_t

    pre_t = cur_t

print(res)

Submission status: Accepted

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

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

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

X = N * T - discount

print(X)

Submission status: Accepted

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

tn=T
ans=T
for i in range(n):
    if tn <= t[i]:
        ans+=T
        tn=t[i]+T
    else:
        ans+=(T-(tn-t[i]))
        tn=t[i]+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()]

ans=0
for i in range(n-1):
    start=t[i]
    end=start+T
    if(end>t[i+1]):
        ans+=t[i+1]-t[i]
    else:
        ans+=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):
    ans += min(t[i] - t[i-1], T)
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(1, n):
    ans += min(t[i] - t[i-1], T)
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(1,n):
    ans += min(T[i]-T[i-1],t)
print(ans+t)

Submission status: Accepted

Solution code:
from sys import stdin

n,t = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

point = 0

lin = []

for i in range(1,n):
    lin.append(li[i]-li[i-1])

for i in lin:
    if i <= t:
        point += i
    else:
        point += t

point += t

print(point)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

now = -1
ans = 0
for i in range(N):
    if now <= t[i]:
        ans+=T
        now = T+t[i]
    else:
        ans+=T
        ans-=now-t[i]
        now = T+t[i]
        
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(N-1):
	# print('ボタンを押す時間:',t[i])
	if abs(t[i+1]-t[i]) > T:
		time += T
	else:
		time += abs(t[i+1]-t[i])
	# print('累計:',time)

print(time+T)

Submission status: Accepted

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

ans = 0
for i in range(n-1):
  ans += min(li[i+1]-li[i],t)
ans += t
print(ans)

Submission status: Accepted

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

  total = 0

  for i in range(1,len(ni)) :
    delta = ni[i] - ni[i-1]
    if delta < t :
      total += delta
    else :
      total += t

    
  print(total+t)

main()

Submission status: Accepted

Solution code:

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)

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)


main()

Submission status: Accepted

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

total = 0

for i in range(1,len(ni)) :
  delta = ni[i] - ni[i-1]
  if delta < t :
    total += delta
  else :
    total += t

    
print(total+t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
now = 0
res = 0
a = list(map(int,input().split()))
for i in a:
    if i>=now:
        res+=t
        now=i+t
    else:
        res+=i+t-now
        now = i+t
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(n-1):
    if a[i+1] - a[i] > t:
        count += t
    else:
        count += a[i+1] - a[i]

count += t

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

# main
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())
a=list(map(int,input().split()))
total=0
for i in range(len(a)-1):
    if a[i+1]-a[i]>=t:
        total+=t
    else:
        total+=a[i+1]-a[i]
print(total+t)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

result = 0
for i, s in enumerate(schedule):
  if (i + 1) > len(schedule) - 1:
    continue
  a = schedule[i + 1] - s
  if a > t:
    a = t
  result += a
result += t

print(result)

Submission status: Accepted

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

T = [int(i) for i in input().split()]
res = 0
for i in range(len(T)-1):
    d = T[i+1] - T[i]
    if  d > m:
        res += m
    else:
        res += d
print(res + m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def examC():
    N, T = LI()
    t = LI()
    cur = T
    before = 0
    for i in t[1:]:
        cur += min(T,i-before)
        before = i
    print(cur)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

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

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
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, T] = string_to_int(inputs[0])
    P = string_to_int(inputs[1])

    count = 0
    prev = 0
    for p in P:
        if p == 0:
            continue
        else:
            if p - prev < T:
                count += p - prev
            else:
                count += T
        prev = p
    count += T
    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num = 0
for i in range(1, N):
    sbn = tlist[i] - tlist[i - 1]
    if sbn < T:
        num += sbn
    else:
        num += T
num += T
print(num)

Submission status: Accepted

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

wait=[0]*len(h)
for i in range(len(wait)-1):
  wait[i]=h[i+1]-h[i]
wait[len(wait)-1]=t

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

print(ans)

Submission status: Accepted

Solution code:
a = list(input().split(" "))
b = list(input().split(" "))
t = 0
for k, i in enumerate(b):
    if k < len(b)-1:
        if int(i)+int(a[1]) > int(b[k+1]):
            t += int(b[k+1]) - int(b[k])
        else:
            t += int(a[1])
    else:
        t += int(a[1])
print(t)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = T
    end = T
    for ti in t[1:]:
        if end < ti:
            ans += T
        else:
            ans += T - (end - ti)
        end = ti + T
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
Data = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    ans += min(T,(Data[i+1]-Data[i]))
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(len(t)):
    if i == len(t)-1:
        ans += T
    elif t[i+1] - t[i] < T:
        ans += t[i+1] - t[i]
    else:
        ans += T
print(ans)

Submission status: Accepted

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

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

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

print(sum)

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

print(ans+T)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, t: "List[int]"):
    answer =0 
    for i in range(N-1):
        answer += min(t[i+1]-t[i],T)
    
    answer += T
    print(answer)


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    t = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, T, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

d=[T-(t[i+1]-t[i]) for i in range(N-1) if t[i+1]-t[i]<T]
print(N*T-sum(d))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    T, *tn = map(int, open(0).read().split()[1:])
    print(tn[-1] + T - sum(t2 - t1 - T
                           for t1, t2
                           in zip(tn[0:], tn[1:])
                           if t2 - t1 > T))
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    print(tn[-1] + T - sum(t2 - t1 - T
                           for t1, t2
                           in zip(tn[0:], tn[1:]) if t2 - t1 > T))
    return


main()

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    print(tn[-1] + T - sum(t2 - t1 - T for t1, t2 in zip(tn[0:], tn[1:]) if t2 - t1 > T))
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    ans = 0
    for t1, t2 in zip(tn[0:], tn[1:]):
        ans += min(T, t2 - t1)
    ans += T
    print(ans)
    return


main()

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]

print(ans+T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
time = list(map(int,input().split())) + [float('inf')]

ans = 0
for i in range(n):
    ans += min(t,time[i+1]-time[i])
print(ans)

Submission status: Accepted

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

ans, lt = t, 0
for nt in T:
    if nt <= lt + t:
        ans += (nt - lt)
    else:
        ans += t
    lt = nt

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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())
time = [int(i) for i in input().split()]
ans = T  
now = 0 
for i in range(N-1):
  now = time[i] + T
  if now > time[i+1]:
    ans += (time[i+1]-time[i]) 
  else:
    ans += T
print(ans)

Submission status: Accepted

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

ans = t
stop = t

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

print(ans)

Submission status: Accepted

Solution code:
# C - Sentou

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

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

Submission status: Accepted

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

print(res + t)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC071 C - Sentou
N,TT = map(int,input().split())
T = list(map(int,input().split()))

ans = 0
start = 0

if len(T) == 1:
    ans = TT + T[0]
    print(ans)
    exit()

for i in range(N-1):
    if i == N-2:
        if T[i+1]-T[i] >= TT:
            ans += TT
        else:
            ans += TT+T[i+1]-start
    if T[i+1]-T[i] >= TT:
        ans += TT+T[i]-start
        start = T[i+1]
    elif T[i+1]-T[i] < TT:
        pass
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,T=map(int,input().split())
X=list(map(int,input().split()))

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

print(all+T)

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n, T = map(int, input().split())
    ts = list(map(int, input().split()))

    # last_time = ts[0]
    ans = T
    for i in range(1, n):
        ans += min(ts[i] - ts[i - 1], T)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n, T = na()
  t = na()

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

main()

Submission status: Accepted

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