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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    arr = [[]] * len(t)
    for i in range(len(t)):
        arr[i] = [t[i], t[i]+T]

    ans = arr[0][1]
    for i in range(len(t)-1):
        _, t1 = arr[i]
        f2, t2 = arr[i+1]

        if t1 <= f2:
            ans += t2 - f2
        else:
            ans += t2 - t1
    print(ans)


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
l = list(map(int, input().split()))
l_sa = []
for i in range(n - 1):
    l_sa.append(l[i + 1] - l[i])
for i in range(n - 1):
    if l_sa[i] > t:
        l_sa[i] = t
print(sum(l_sa) + 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, t[i+1]-t[i])
print(ans+T)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
TL = [-T] + list(map(int, input().split()))

answer = 0
for i in range(1, N+1):
    answer += T
    answer -= max(0, TL[i-1] + T - TL[i])
print(answer)

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 + 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 = tuple(map(int, input().split()))
ans = T
for i in range(n-1):
    if 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())
tl = list(map(int, input().split()))

tl.append(float("inf"))

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in t:
    if hotwater < i:
        ans += T
        hotwater = i + T
    else:
        ans += i - (hotwater - T)
        hotwater = i + T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

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

print(count)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
ls = list(map(int, input().split()))
e = 0
res = 0
for s in ls:
    ne = s + t
    res += ne - e if s <= e else t
    e = ne
print(res)

Submission status: Accepted

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

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


now = 0
ans = 0
for i in range(n-1):
    if arr[i+1]-arr[i] <= t:
        ans += arr[i+1]-arr[i]
    else:
        ans += t

ans += t

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    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)
resolve()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
X = 0
start = 0
stop = 0
for t in map(int, input().split()):
  if t > stop:
    X += stop - start
    start = t
  stop = t + T
X += stop - start
print(X)

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import deque

N, T = [int(n) for n in input().split()]
Q = deque([int(n) for n in input().split()])

def main():
    ans = 0
    while Q:
        curr = Q.popleft()
        next = Q[0] if Q else float('inf')
        ans += min(T, next - curr)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n,t=map(int,input().split(' '))
    human = list(map(int,input().split(' ')))
    ans = t
    for i in range(n-1):
        if human[i+1]-human[i] >= t:
            ans += t
        else:
            ans += human[i+1] - human[i]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# なんかもうこれめちゃくちゃ解きにくい

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

x = t
for i in range(n - 1):
    x += min(arr[i + 1] - arr[i], 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(1,N):
  if t[i-1]+T>t[i]:
    ans += t[i]-t[i-1]
  else:
    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(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=map(int,input().split())
A=list(map(int,input().split()))
s=t
for i in range(n-1):
  s+=t if A[i+1]-A[i]>=t else A[i+1]-A[i]
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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()))

cnt = 0

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

print(cnt)

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()))

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

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

total = 0
for i in range(n):
    if i == n-1:
        total += t
    else:
        aida = tlist[i+1] - tlist[i]
        if aida <= t:
            total += aida
        else:
            total += t
print(total)

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, T[i+1] - T[i])

print(ans + t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = [int(x) for x in input().split()]
ret = 0
pre = 0
for t in [int(x) for x in input().split()]:
  ret += min(T, t - pre)
  pre = t
else:
  ret += T
print(ret)

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)
ans += T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
T=[int(i) for i in 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:
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())
tn = list(map(int, input().split()))

st = 0
now = 0
for ti in tn:
  st += t - max(0, (now - ti))
  now = ti + t
  
print(st)

Submission status: Accepted

Solution code:
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Accepted

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

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

print(total)

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

Submission status: Accepted

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

ans = T

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

print(ans)

Submission status: Accepted

Solution code:
import bisect


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

ans = 0
start = 0
end = 0

for i, t in enumerate(ts):
    if i == 0:
        start, end = t, t + T
        continue

    # assert start <= t
    if t <= end:
        end = t + T
    else:
        ans += (end - start)
        start, end = t, t + T

ans += (end - start)
print(ans)

Submission status: Accepted

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

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

ans = T
tmp = T

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

Submission status: Accepted

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

c=1
d=0
for i in range(n-1):
    z=t[i+1]-t[i]
    if z>=T:
        c+=1
    else:
        d+=z
print(c*T+d)

Submission status: Accepted

Solution code:
import numpy as np
n,t = list(map(int, input().split()))
s = list(map(int, input().split()))
s_diff = np.diff(s)
print(sum([t if t < s_diff[i] else s_diff[i] for i in range(n-1)]) + t)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc060/tasks/arc073_a
# C - Sentou

N, T = list(map(int, input().split()))
t_list = list(map(int, input().split()))
total = 0

for i in range(1, N):
    diff = t_list[i] - t_list[i-1]
    if diff < T:
        total += diff
    else:
        total += T
total += T

print(total)

Submission status: Accepted

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

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

X += T
print(X)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = T
now = 0
for i in range(N):
    if  i == 0:
        now = t[i]
        continue
    if now+T <= t[i]:
        res += T
        now =  t[i]
    else:
        res += t[i]-now
        now = t[i]
print(res)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


def main():
    num, time_lim = map(int, input().split())
    data = list(map(int, input().split()))

    ans = 0
    next_time = 0
    for i in range(num):
        now_time = data[i]
        if now_time >= next_time:
            next_time = now_time + time_lim
            ans += time_lim
        else:
            ans += now_time + time_lim - next_time
            next_time = now_time + time_lim
        # print(ans, now_time)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N,T = LMIIS()
    people = LMIIS()
    sumtime = T
    pre = people[0]
    for i in range(1,N):
        tmp = people[i]
        sumtime += min(tmp-pre,T)
        pre = tmp
    print(sumtime)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
Timers = [int(i) for i in input().split()]
subTs = [0] * N
for t in range(1, N):
    subTs[t] = Timers[t] - Timers[t - 1]

score = T * N
time = T
for i in range(1, N):
    # お湯でている時にスイッチが押された場合
    if subTs[i] < time:
        lost = T - subTs[i]
        score -= lost
print(score)

Submission status: Accepted

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

dup_time = 0

for i in range(1,N):
    if t_list[i] - t_list[i-1] < T:
        dup_time += T - (t_list[i] - t_list[i-1])

print(N*T - dup_time)

Submission status: Accepted

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

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

ans+=T

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



n, t = LI()
nums = LI()


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


print(ret)

Submission status: Accepted

Solution code:
# coding: utf-8
n, t = map(int, input().split())
a = list(map(int, input().split()))

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

sum += t
print(sum)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, T = map(int, input().split())
L = [int(v) for v in input().split()]

ans = 0
pos = 0
for i in range(N):
    v = L[i]
    if pos > v:
        ans += v + T - pos
    else:
        ans += T

    pos = v + T

print(ans)

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

ans+=t
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
sum = 0
current = 0

for tt in t:
  if current <= tt:
    current = tt+T
    sum += T
  else:
    diff = current - tt
    current = tt+T
    sum += T - diff
print(sum)

Submission status: Accepted

Solution code:
import numpy
n, t = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a = a[1:] - a[:n-1]
a[a > t] = t
print(a.sum() + t)

Submission status: Accepted

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

Submission status: Accepted

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

ans = T
tmp = 0

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

print(ans)

Submission status: Accepted

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

x = N*T
p = 0

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

print(x-p)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = T
tmp = 0

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

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
a = tuple(map(int, input().split()))
b = tuple(a_ato - a_mae for a_ato, a_mae in zip(a[1:], a))
print(sum(map(lambda x: min(x, t), b)) + t)

"""
最後の人が出したシャワーは、時間いっぱい出る
それ以前の人が出したシャワーは、
時間いっぱいか、次の人が押すまでの時間のうち、短い時間だけ出る
"""

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = T
whenFinish = T
for t in TList:
    if t >= whenFinish:
        ans += T
        whenFinish = t + T
    else:
        ans += T - (whenFinish - t)
        whenFinish = t + T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
f = 0
res = 0

for e in a:
    if e <= f:
        f = e+t
    else:
        res += f-s
        s = e
        f = s+t
res += f-s
print(res)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, T = inpl()
t = inpl()
offtime = sum(max(0, t[i+1]-t[i]-T) for i in range(N-1))
print(t[-1]+T-offtime)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
Sum = []
lis = list(map(int,input().split()))
for i in range(N-1):
  Sum.append(lis[i+1]-lis[i])
for k in range(len(Sum)):
  if Sum[k] > T:
    Sum[k] = T
print(sum(Sum)+T)

Submission status: Accepted

Solution code:
import sys

#+++++
		
def main():
	n,t = map(int, input().split())
	tl=list(map(int, input().split()))
	
	counter=0
	pre_end=0
	for ti in tl:
		if ti < pre_end:
			counter+=t+ti-pre_end
		else:
			counter+=t
		
		pre_end=ti+t
	
	print(counter)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v.copy()
    return [nlist(n[1:], v) for _ in range(n[0])]

# バイナリインデックス木
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            s %= MOD
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# エントリーポイント
def main():
    N, T = input(int, int)
    A = input([int, N])

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

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

Submission status: Accepted

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

total=t
for i in range(1,len(Ts)):
    if(Ts[i] - Ts[i-1]>t):
        total += t
    else:
        total += Ts[i] - Ts[i-1]

print(total)

Submission status: Accepted

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

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

print(res)

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