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:
import sys
input = sys.stdin.readline
N, T = map(int, input().split())
ts = [int(x) for x in input().split()]

now = 0
ans = 0
for t in ts :
    if t >= now :
        ans += T
    else :
        ans += T - (now - t)
    now = t + T

print(ans)

Submission status: Accepted

Solution code:
#ABC060

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

s = [0]+[l[i+1] - l[i] for i in range(len(l)-1)]
#print(s)

m = 0
for i in range(n):
    m += min(t,s[i])
print(m+t)

Submission status: Accepted

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

N,T = list(map(int, input().rstrip().split()))
t_list = list(map(int, input().rstrip().split()))
#-----

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

cnt += T

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans + T)

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

print(ans)

Submission status: Accepted

Solution code:
n,tt = map(int, input().split( ))
t = tuple(map(int, input().split( )))
ans  = 0
ti = 0;
for i in range(n):
    if t[i] >= ti+tt:
        ans += tt 
    else:
        ans += t[i] - ti
    ti = t[i]
print(ans+tt)##最後の分

Submission status: Accepted

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

u = []
for i in range(1,N):
    tmp = t[i-1] + T - t[i]
    if tmp > 0:
        u.append(t[i-1] + T - t[i])
    else:
        u.append(0)
print(T*N - sum(u))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

answer = 0
prev = -10 * T


for t in intervals:
    if t >= prev + T:
        answer += T
    else:
        answer += t - prev
    prev = t

print(answer)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,T=MI()
    t=LI()
    t.append(t[-1]+T+5)
    ans=0
    for i in range(N):
        if t[i+1]-t[i]<=T:
            ans+=t[i+1]-t[i]
        else:
            ans+=T
    print(ans)

main()

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
t=input().split()
a=[int(b) for b in t]
time=0
for c in range(N-1):
    if a[c+1]-a[c]>=T:
        time+=T
    else:
        time+=a[c+1]-a[c]
time+=T
print(time)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, list(input().split(' ')))
ti = list(map(int, list(input().split(' '))))
result = t
for i, item in enumerate(ti):
  temp = t
  if i == len(ti) - 1:
    break
  if ti[i+1] - ti[i] < t:
    temp = ti[i+1] - ti[i]
  result = result + temp

print(result)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N, T = read_values()
    A = read_list()
    res = T
    for i in range(N - 1):
        res += min(A[i + 1] - A[i], T)

    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
time=0
for i in range(len(a)-1):
    time+=max(0,(a[i]+t)-a[i+1])
print(n*t-time)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt+T)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(r+T)

Submission status: Accepted

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

r = 0

for i in range(0, n - 1):
    r += min(t, x[i+1] - x[i])
r += t

print(r)

Submission status: Accepted

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

ans = t

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

Submission status: Accepted

Solution code:
def main():
    people_num, emit_time = map(int, input().split())
    times = list(map(int, input().split()))
    answer = 0
    for i in range(1, people_num):
        if times[i] - times[i - 1] > emit_time:
            answer += emit_time
        else:
            answer += times[i] - times[i - 1]
    answer += emit_time
    print(answer)


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

Submission status: Accepted

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

ans = 0
start = lst1[0]
now = lst1[0]+t
for i in range(1,n):
    if now > lst1[i]:
        now = lst1[i]+t
    else:
        ans += now - start
        now = lst1[i] + t
        start = lst1[i]

ans += now-start

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, T, *t = map(int, read().split())
ans = 0
for cur, nex in zip(t, t[1:]):
    ans += min(T, nex - cur)
print(ans + T)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
A = [int(x) for x in input().split()]
ans = T
endtime = T
for i in range(1, N):
    ans += min(T, A[i] + T-endtime)
    endtime = A[i] + T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
tt=list(map(int,input().split()))
count=0
i=1
while(i<n):
	if tt[i]-tt[i-1]>=t:
		count+=t
	else:
		count+=tt[i]-tt[i-1]
	i+=1
print(count+t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
t = list(map(int, input().split()))
p = -1
ans = 0
for ti in t:
  ans += d - max(p - ti, 0)
  p = ti + d
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):
    a = t[i+1]-t[i]
    ans += min(T,a)
ans += T 
print(ans)

Submission status: Accepted

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

ans = 0
tmp = 0
for i in tt:
    ans += min(t, i+t - tmp)
    tmp = i+t
print(ans)

Submission status: Accepted

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

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

print(t[-1] + T - stop)

Submission status: Accepted

Solution code:
def showertime(n , t , tl):
    ans = 0
    for i in range(n):
        ans += t
        if i != 0 and tl[i] - tl[i-1] < t:
            ans -= t - (tl[i] - tl[i-1])

    return ans

def main():
    n , t = map(int , input().split())
    tl = list(map(int , input().split()))
    print(showertime(n , t , tl))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

time = times[-1] + t

for i in range(1, n):
    if times[i] - times[i-1] > t:
        time -= times[i] - times[i-1] - t


print(time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
s = 0
end = 0
 
for i in range(n):
  if (L[i] + t) > end:
    if L[i] < end:
      s += (L[i] + t - end)
    else:
      s += t
  end = (L[i] + t)
print(s)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])
#print(L)

ri = 0
sum = 0

for x,y in L:
#  print(x,y)
  if ri > x:
#    sum += y - sum
    sum += y - ri
  else:
    sum += b
  ri = y
#  print("sum:" + str(sum), "ri:" + str(ri))

print(sum)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])
#print(L)

ri = 0
sum = 0

for x,y in L:
#  print(x,y)
  if ri > x:
    sum += y - ri
  else:
    sum += b
  ri = y
#  print("sum:" + str(sum), "ri:" + str(ri))

print(sum)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])
#print(L)

ri = 0
sum = 0

for x,y in L:
#  print(x,y)
  if ri > x:
    sum += y - ri
    ri = y
  else:
    sum += b
    ri = y
#  print("sum:" + str(sum), "ri:" + str(ri))

print(sum)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in range(1,N):
  a=A[i]-A[i-1]
  if a<=T:
    cnt+=a
  else:
    cnt+=T
print(cnt+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):
    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:
#!/usr/bin/env python3
n,time = map(int,input().split())
t = list(map(int,input().split()))
ans = 0
for i in range(1,n):
	if t[i] - t[i-1] <= time: ans += t[i] - t[i-1]
	else: ans += time
print(ans+time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
def f(t,t1):
    return min(t - t1,T)
t.append(0)
t.sort()
ans = 0
for i in range(N):
    x = t[i+1]
    y = t[i]
    ans += f(x,y)
ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, dt, T):
    total = dt
    prev = T[0]
    for t in T[1:]:
        if dt <= t - prev:
            total += dt
        else:
            total += t - prev
        prev = t
    return total

_n, _dt = map(int, input().split())
_T = list(map(int, input().split()))
print(solve(_n, _dt, _T))

Submission status: Accepted

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

elapsed_t = 0
ans = 0

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

Submission status: Accepted

Solution code:

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

cnt = 0
prev = None

for i in range(n):
  cnt += t

  # 途中で次がくる場合
  if prev != None and (T[i] - prev) < t:
    cnt -= t - (T[i] - prev)

  prev = T[i]


print(cnt)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
tt = list(map(int, input().split()))
print(sum(min(T, t2 - t1) for t1, t2 in zip(tt, tt[1:]+[10**10])))

Submission status: Accepted

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

print(gokei+t)

Submission status: Accepted

Solution code:
# N 人
# T秒お湯が出る

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

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

start = t[0]
end = t[0] + T
ans = 0
for n in range(0, N):
    # 終わってからボタンを押す
    if end <= t[n]:
        # お湯でた時間を記録
        ans += end - start
        # 初期値をボタンを押したときにする
        start = t[n]
        end = t[n] + T
        
        
    # 最大時間 より先にボタンを押す(追加)
    if end > t[n]:
        end = t[n] + T
    
ans += end - start
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
t = LIST()
t = [0] + t
t = [t[i]-t[i-1] for i in range(1, N+1)]
# print(t)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

from operator import mul
from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


# import random
# import time

n, t = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.append(sys.maxsize)

l_continuous = [[]]
l_distinct = []
k = 0

continuous_flag=0

i=0
while i<n:
    if a[i] + t >= a[i + 1]:
        continuous_flag=1
        l_continuous[k].append(i)
        i+=1
    else:
        if continuous_flag==1:
            l_continuous[k].append(i)
            continuous_flag=0
            k+=1
            l_continuous.append([])
        else:
            l_distinct.append(i)
            
        i+=1
del i

ans = 0
for i in range(len(l_continuous)):
    if l_continuous[i].__len__() > 0:
        ans += a[max(l_continuous[i])] - a[min(l_continuous[i])] + t
for i in range(len(l_distinct)):
    ans += t
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N, T = [int(x) for x in input().split()]
    t = [int(x) for x in input().split()]

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


    print(ans + T)
    
    
    

if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
n, t = map(int, input().split())
T = [int(i) for i in input().split()]
x = 0
start = 0
finish = 0
for i,j in enumerate(T):
    if i == n-1:
        if j >= finish:
            x += finish - start + t
        else:
            x += j - start + t
        print(x)
        sys.exit()
    if j >= finish:
        x += finish - start
    else:
        x += j - start
    start = j
    finish = j + 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)
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):
    if i == N-1 or t[i] + T < t[i+1]:
        ans += T
    else:
        ans += t[i+1] - t[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, T = LI()
    t = LI()
    t = t[::-1]
    prev_time = t[0]
    tot = T
    for i, time in enumerate(t[1:]):
        if time + T < prev_time:
            tot += T
        else:
            tot += (prev_time - time)
        prev_time = time
    print(tot)
main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
sum = 0
for i in range(N-1) :
    if t[i+1] - t[i] <= T :
        sum += t[i+1] - t[i]
    else :
        sum += T
sum += T
print(sum)

Submission status: Accepted

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

loss_time_sum = 0
last_finished_time = T

for i in range(1, N):
    current = times[i]
    loss_time_sum += max(0, last_finished_time - current)
    last_finished_time = current + T
print(N * T - loss_time_sum)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,t=MI()
    tt=LI()
    ans=n*t
    for t0,t1 in zip(tt,tt[1:]):
        ans-=max(t-t1+t0,0)
    print(ans)

main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = sorted(map(int, input().split()))  # 入力のときに N を使う必要はありません
answer = T

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
now = 0
for i in range(n):
    if now > tm[i]:
        ans += (tm[i]+t)-now
        now = tm[i]+t

    else:
        ans += t
        now = tm[i]+t
        pass
    #print(ans)

print(ans)

Submission status: Accepted

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

print(ans + T)

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
t.append(10**18)
ans = 0
for t1,t2 in zip(t[:-1],t[1:]):
    if t2-t1 < T:
        ans += t2-t1
    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):
    ans += min(T, t[i+1] - t[i])

ans += T

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

total = 0

for i in range(N):
    if i == N - 1:
        total += T
    else:
        total += min(T, ts[i + 1] - ts[i])

print(total)

Submission status: Accepted

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

Submission status: Accepted

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