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())
t = list(map(int, input().split()))
ans = T
pre = 0
for ti in t[1:]:
  ans += min(T, ti - pre)
  pre = ti

print(ans)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
t=list(map(int,input().split()))
t.append(t[N-1]+T)
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)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

#最後に押してからT秒は必ずお湯が出る
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())
li = list(map(int,input().split()))
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:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,t = LI()
    switch = LI()
    ans = t

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = N * T # 総和
cur = 0 # いつまで出るか
for i in range(N):
    if cur > t[i]:
        ans -= cur - t[i]
    cur = 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(N-1):
    ans += min(T, t[i+1] - t[i])
print(ans+T)

Submission status: Accepted

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

cnt = time
tmp = T[0]
for t in T[1:]:
    if t <= tmp + time:
        cnt += t - tmp
    else:
        cnt += time
    tmp = t

print(cnt)

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

Submission status: Accepted

Solution code:
from sys import stdin

n,t = [int(x) for x in stdin.readline().strip().split()]
t_lst = [int(x) for x in stdin.readline().strip().split()]
diff_lst = [min(t, t_lst[i+1]-t_lst[i]) for i in range(len(t_lst)-1)]
print(sum(diff_lst) + t)

Submission status: Accepted

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

ans = T

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

print(ans)

Submission status: Accepted

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

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

print(ans+time)

Submission status: Accepted

Solution code:
import collections
import sys
import math
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+=A[i+1]-A[i]
    else:
        ans+=T
print(ans+T)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
sum = T
before = t[0]
for ti in t[1:]:
    temp = ti-before
    if temp < T:
        sum += temp
    else:
        sum += T
    before = ti
print(sum)

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]
    
print(time+T)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

cnt = n*T
for i in range(1, n):
    diff = t[i]-t[i-1]
    if diff < T:
        cnt -= T-diff

print(cnt)

Submission status: Accepted

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

s_on = lt[0]
end = s_on+t
ans = t
for _t in lt[1:]:
    if _t <= end:
        ans += _t+t-end
    else:
        ans += t
    end = _t+t

print(ans)

Submission status: Accepted

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

ans = 0

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

ans += T
print(ans)

Submission status: Accepted

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

result = 0
for i in range(n - 1):
  if times[i] + t > times[i + 1]:
    tmp = times[i+1] + t - (times[i] + t)
    result += tmp
  else:
    result += t

print(result + t)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
start = 0
stop = 0
for ti in t:
  if ti >= stop:
    ans += stop - start
    start = ti
  stop = ti+T
print(ans)

Submission status: Accepted

Solution code:
import itertools
n, t = map(int,input().split())
tl = list(map(int,input().split()))

water = 0
for i in range(1,n):
    diff = tl[i]-tl[i-1]
    if diff <= t:
        water += diff
    else:
        water += t
water += t
print(water)

Submission status: Accepted

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

t = list(map(int, input().split()))
diff = []

for i in range(1, N):
    diff.append(t[i]-t[i-1])
diff.append(T)

ans = 0
for d in diff:
    ans += min(T, d)
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):
    if i==0:
        s=0
        l=a[i]+t
        continue

    if a[i]<=l:
        l=a[i]+t
    else:
        ans+=l-s
        s=a[i]
        l=a[i]+t


ans+=l-s
print(ans)

Submission status: Accepted

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

# 最後にN秒流れて終わり
ans += T

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,t,*s=map(int,open(0).read().split())
ans=0
e=0
for i in s:
    if e > i:
        ans += t - e + i
    else:
        ans += t
    e = i + t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
X=list(map(int,input().split()))+[float("inf")]

A=0
B=0
S=0
for t in X:
    if B<t:
        S+=B-A
        A=t
    B=t+T

print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
end = -1
start = -1
for x in t:
    if end < x:
        ans += (end - start)
        start = x
        end = x + T
    else:
        end = x + T

ans += (end - start)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, T = mapint()
Ts = list(mapint())

ans = 0
last = 0
for t in Ts:
    ans += min(t-last, T)
    last = t

print(ans+T)

Submission status: Accepted

Solution code:
def resolve():
  N, T = map(int, input().split())
  t = list(map(int, input().split()))
  ans = 0
  till = 0
  for now in t:
    if till > now:
      ans -= till - now
    till = now + T
    ans += T
  print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,t=list(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+=a[i]-a[i-1]
  else:
    ans+=t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, h = [int(x) for x in input().split()]
    t = [int(x) for x in input().split()]
    total = 0
    off = 0
    for e in t:
        if e >= off:
            total += h
        else:
            total += h - (off - e)
        off = e + h
            
    print(total)
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

1 + k



"""

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = t

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

print(ans)

Submission status: Accepted

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

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

print(m + t)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,t,*a = map(int,read().split())


ans = 0

s = a[0]
for i in a:
    s = max(i,s)
    ans += i+t-s
    s = i+t

print(ans)

Submission status: Accepted

Solution code:
def main():
    N,T=map(int,input().split())
    t=list(map(int,input().split()))
    s = 0
    c = 0
    for t1 in t:
        c = max(c, t1)
        if c > t1:
            s += t1 - c + T
            c += t1 - c + T
        else:
            s += T
            c += T
    print(s)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import copy

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,t = readInts()
ts = readInts()
end = ts[0]+t
ans = t

for i in ts:
	ans+=min(t-(end-i),t)
	end = i+t

print(ans)

Submission status: Accepted

Solution code:
# from pprint import pprint
# import math
# import collections

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

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

    # print(i, total)
total += T

print(total)

Submission status: Accepted

Solution code:
import numpy as np
N, T = map(int, input().split())
t = np.array(tuple(map(int, input().split())))
s = t[1:]-t[:-1]-T
S = int(sum(s[s < 0]))
print(N*T+S)

Submission status: Accepted

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

prev = ts[0]
cnt = 0
for t in ts[1:]:
    # print(t,prev)
    cnt += min(T, t - prev)
    prev = t
print(cnt+T)

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 i==0: #1st 
    end = T #お湯が止まる時間
  
  elif t[i]>end: 
    X+=T
  elif t[i]<=end:
    X+=t[i]-t[i-1]
    
  end = t[i]+T

X+=T #last
print(X)

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

end = 0;
ans = 0;
for i in range(N) :
    if end > t[i] :
        ans += t[i] + T - end;
    else :
        ans += T;
    end = t[i] + T;
    #print(ans,end);

print(ans);

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n, t = map(int, input().split())
query = list(map(int, input().split()))
ans = 0
for i in range(1, n):
    interval = query[i] - query[i - 1]
    ans += min(t, interval)

# 最後の一回分
ans += t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
flag=False
for i in range(0,len(ts)):
  #print(ts[i],flag)
  if flag:
    if ts[i]-ts[i-1] <= t:
      ans+=ts[i]-ts[i-1]
    else:  
      ans+=t
  else:
    if ts[i]<=t and i!=len(ts)-1:
      ans=ts[i+1]
    else:
      if ts[i]-ts[i-1] <= t:
        ans=ts[i]
        
      else:  
        ans=ts[i-1]+t
        flag=True
  #print("ans",ans)

print(ans+t)

Submission status: Accepted

Solution code:
import numpy as np
N, T = map(int, input().split())
t = list(map(int, input().split()))
timer = np.zeros(N)

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

timer = timer - T
timer[0] = 0


print(int(t[-1]+T - sum(timer)))

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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 19:48:52 +0900
# LastModified: 2020-06-26 20:06:44 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, t = map(int, input().split())
    time = list(map(int, input().split()))
    total = 0
    for i in range(0,n-1):
        cur = time[i]
        nex = time[i+1]
        if cur+t+1<=nex:
            total += t
        else:
            total += nex-cur
#        print(total)
    print(total+t)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
N,T=map(int, input().split())
time = list(map(int, input().split()))

ans = T

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for each in cum_sub[1:]:
  ans += min(T, each)
  
ans += T
print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
tl=list(map(int,input().split()))+[10**10]

ans=0
bef=0
for i in range(1,n+1):
  t_ans=t
  e_time=tl[i-1]+t
  if e_time>tl[i]:
    t_ans-=e_time-tl[i]
  ans+=t_ans
print(ans)

Submission status: Accepted

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

if N == 1:
  print(T)
  exit(0)
  
for i in range(1,N):
  dff = t[i] - t[i -1]
  dff_list.append(dff)
  
ans_list = [T if T <= i else i for i in dff_list]

ans = sum(ans_list) + T
print(ans)

Submission status: Accepted

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

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

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

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

    print(ans)


if __name__ == "__main__":
    main()

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 += T
    if t[i]-t[i-1] < T:
        # 稼働中にスイッチが押されたらオーバーラップ分を引く
        ans -= (t[i-1] + T - t[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
*t,=map(int,input().split())
ans=0
i=0
while i<N-1:
    ans+=min(T,t[i+1]-t[i])
    i+=1
ans+=T
print(ans)

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
a=list(input().split())
ts=[]
for _ in range (len(a)):
    ts.append(int(a[_]))

YU=T

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

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline()

def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))
    kaishi = 0
    syuuryou = 0
    time = 0
    for i in t:
        if syuuryou < i:
            time += syuuryou - kaishi
            kaishi = i
        syuuryou = i + T
    time += syuuryou - kaishi 
    print(time)
    
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, t[i]-t[i-1])
print(ans+T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
ans = 0
t_start = 0
t_stop = 0
for t in map(int, input().split()):
    if t >= t_stop:
        ans += t_stop - t_start
        t_start = t
    t_stop = t + T
print(ans + t_stop - t_start)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
T = list(map(int, input().split()))
ans = t
for a, b in zip(T, T[1:]):
	ans += min(b - a, t)
print(ans)

Submission status: Accepted

Solution code:

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


ans=0

for e in range(1,n):
    if T<=(t[e]-t[e-1]):
        ans+=T

    else:
        ans+=(t[e]-t[e-1])

print(ans+T)

Submission status: Accepted

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

print(ans+T)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
from itertools import tee


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


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

for p, n in pairwise(ts + [ts[-1] + T]):
    if n - p >= T:
        s += T
    else:
        s += n - p
print(s)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import bisect
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,t = map(int,read().split())
    li = list(map(int,read().split()))
    now = -1e18
    ans = 0
    for ti in li:
        if now < 0:
            now = ti
        else:
            ans += min(t,ti-now)
            now = ti
        
    print(ans+t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    N, T = map(int,input().split())
    t = list(map(int,input().split()))
    prev = 0
    end = 0
    ans = 0
    for e in t:
        if end < e:
            ans += end-prev
            prev = e
            end = e + T
        else:
            end = e + T
    ans += end - prev
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import pi

def solve():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    S = [int(i) for i in input().split()]
    count = 0
    S.append(10 ** 20)
    for i in range(1, N+1):
        if S[i] > S[i-1] + T: count += T
        else: count += S[i] - S[i-1]
    print(count)

    return 0

if __name__ == "__main__":
    solve()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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())
T = list(map(int, input().split()))
ans = 0
x_ = 0
for x in T:
    if x-x_ >= t:
        ans += t
    else:
        ans += x-x_
    x_ = x
ans += t
print(ans)