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

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

print(total+T)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,Time = MI()
    T=LI()
    ans = 0
    end = -1
    for t in T:
        if end < t:
            ans += Time
            end = t+Time
        else:
            ans += t+Time-end
            end = t + Time
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

out = 0


#最後のだけ残す
for i in range(n-1):
    if tl[i+1] < tl[i]+t:
        out += tl[i+1]-tl[i]
    elif tl[i+1] >= tl[i]+t:
        out += t

out += t

#1回の時はできる
if n == 1:
    out = t

print(out)

Submission status: Accepted

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

a=list(map(int,input().split()))
time=0
for i in range(1,N):
  dt= a[i]-a[i-1]
  if dt<T:
    time+=dt
  else:
    time +=T
time +=T

print(time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
ts = list(map(int, input().split()))
anser = start = end = 0

for t in ts:
  if t <= end:
    end = t + T
  else:
    anser += end - start
    end = t + T
    start = t
print(anser + end - start)

Submission status: Accepted

Solution code:
import numpy as np
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,T = IL()
t = IL()

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

print(ans)

Submission status: Accepted

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

def main():
    _,T = map(int, input().split())
    P = list(map(int, input().split()))
    ans = start = end = 0
    for p in P:
        if start == 0 and end == 0:
            end = T
        else:
            if p < end:
                end = p + T
            else:
                ans += end - start
                start = p
                end = p + T
    ans += end - start
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)

n ,m = ips()
a = iprow()
s = 0
for i in range(n-1):
    if a[i+1]-a[i]>=m:
        s+=m
    else:
        s+=a[i+1]-a[i]

print(s+m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_sentou():
    N, T = [int(i) for i in input().split()]
    Times = [int(i) for i in input().split()] + [float('inf')]  # 番兵追加
    return sum([min(T, Times[i + 1] - Times[i]) for i in range(N)])

print(c_sentou())

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
k=[int(i) for i in input().split()]
ans=[0]*3
for i in k:
    if i<=ans[1]:
        ans[1]=i+t
    else:
        ans[2]+=ans[1]-ans[0]
        ans[0]=i
        ans[1]=ans[0]+t

print(ans[2]+(ans[1]-ans[0]))

Submission status: Accepted

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

for i in range(n-1):
    tElapse = tList[i+1] - tList[i]
    tSum += (t if tElapse > t else tElapse)

print(tSum)

Submission status: Accepted

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

for i in range(n-1):
    if tList[i+1] - tList[i] > t:
        tSum += t
    else:
        tSum += tList[i+1] - tList[i]

print(tSum)

Submission status: Accepted

Solution code:
N, T, *V = map(int, open(0).read().split())
wa = 0
prev = 0
for i in range(N):
  if(V[i] - prev < T):
    wa += V[i] - prev
  else:
    wa += T
  prev = V[i]
  pass
wa += T
print(wa)

Submission status: Accepted

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

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

time = []
for i in range(1, N):
    sub = t[i] - t[i-1]
    time.append(min(sub, T))

time.append(T)

print(sum(time))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
t = [int(i) for i in input().split()]
dif = []
for i in range(N-1):
    dif.append(t[i+1]-t[i])
cnt = 0
for i in range(len(dif)):
    if dif[i] < T:
        cnt += dif[i]
    else:
        cnt += T

print(cnt+T)

Submission status: Accepted

Solution code:
_,T,i,*t=map(int,open(0).read().split());s=T
for j in t:T+=min(s,j-i);i=j
print(T)

Submission status: Accepted

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N, T = map(int, input().split())
    push = list(map(int, input().split())) + [INF]

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

    print(ans)


sol()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
end = 0 + t

for i in range(1, len(l)):
    if l[i] <= end:
        ans += l[i] - l[i-1]
    else:
        ans += t
    end = l[i] + t
ans += t

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
prev_t = -T
for t in X:
  res += min(T, t - prev_t)
  prev_t = t

print(res)

Submission status: Accepted

Solution code:
class AtCoder:
    def main(self):
        N, T = map(int, input().split())
        time = [int(t) for t in input().split()]

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


if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n, t = [int(i) for i in sys.stdin.readline().split()]
t_ls = [int(i) for i in sys.stdin.readline().split()]
diff_ls = []
for i in range(len(t_ls)-1):
    diff = t_ls[i+1] - t_ls[i]
    if diff > t:
        diff_ls.append(t)
    else:
        diff_ls.append(diff)
print(sum(diff_ls) + t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N,T = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in range(N-1):
    if data[i+1] - data[i] >= T:
        ans += T
    else:
        ans += (data[i+1]-data[i])
ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = T * N

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nt=input().split()
n ,t = int(nt[0]),int(nt[1])
tlist=[int(x) for x in input().split()]
#print(n,t,tlist)
pretick =0
total=0
for tick in tlist:
  if tick==0:
    total+=t
  else:
    if pretick + t > tick:
      total+=(tick-pretick)
#      print(pretick,t,tick,tick-pretick,total)
    else:
      total+=t
  pretick=tick
#total+=t
print(total)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

t.append(1145141919810)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N, T = [int(i) for i in input().split()]
A = [int(i) for i in 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:
N, T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

ans = 0
pre = 0
for a in A:
    ans += min(a - pre, T)
    pre = a
print(ans + T)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,T,b,*t=map(int,open(0).read().split())
a=T
for i in t:a+=min(i-b,T);b=i
print(a)

Submission status: Accepted

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

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



print (ans + T)

Submission status: Accepted

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

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

Submission status: Accepted

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


ans = 0
start_time = T[0]
end_time = T[0] + time
for i in range(1, N):
    if T[i] <= end_time:
        ans += T[i] - start_time
        start_time = T[i]
        end_time = T[i] + time
    else:
        ans += time
        start_time = T[i]
        end_time = T[i] + time
ans += time


print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())
    time = [int(t) for t in input().split()]
    start = 0
    cur = 0
    ans = 0
    for t in time[1:]:
        if t - cur > T:
            ans += cur + T - start
            start = t
        cur = t
    ans += cur + T - start
    return ans


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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
ts = list(map(int, input().split()))
r = 0
tend = 0
for t in ts:
  if t > tend:
    r += T
  else:
    r += t+T-tend
  tend = t+T
print(r)

Submission status: Accepted

Solution code:

import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n,t=getints()
ts=getints()

segm = [[s,s+t] for s in ts]

update = True
while update:
    update = False
    new_segm = [segm[0]]
    for i in range(1, len(segm)):
        if new_segm[-1][1] >= segm[i][0]:
            new_segm[-1][1] = segm[i][1]
            update = True
        else:
            new_segm.append(segm[i])
    segm = new_segm

res = 0
for s in segm:
    res += s[1] - s[0]

print(res)

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

Submission status: Accepted

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

total = 0

for t_pre, t_post in zip(ts[:-1], ts[1:]):
  if t_post - t_pre < T:
    total += t_post - t_pre
  else:
    total += T

total += T

print(total)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
T = list(map(int, sys.stdin.readline().split()))

T = np.array(T)

a = np.minimum(np.diff(T), M)
print(a.sum() + M)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, T: int, t: "List[int]"):

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

    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans += t
print(ans)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
tl = list(map(int, input().split()))
tl.append(10 ** 10)
tt = 0
for i, v in enumerate(tl):
    if i == 0:
        te = v + t
    else:
        tt += min(t, 10 ** 10 if te < v else t - (te - v))
        te = v + t
print(tt)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
time = list(map(int, input().split()))
time.append(float('inf'))

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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

print(time())

Submission status: Accepted

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

Submission status: Accepted

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

ret = 0
cur = 0
for tt in t :
    if tt < cur :
        ret += tt + T - cur
    else :
        ret += T
    cur = tt + T
    
print(ret)

Submission status: Accepted

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

kaburi = 0
for i in range(n-1):
    if t[i+1]-t[i]<y:
        kaburi += y-(t[i+1]-t[i])
print(len(t)*y-kaburi)

Submission status: Accepted

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

cnt = 0
time = 0

for i in range(n):
    if time <= lst[i]:
        cnt += t
    else:
        cnt += lst[i] + t - time
    time = lst[i] + t

print(cnt)

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

Submission status: Accepted

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

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

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

print(total)

Submission status: Accepted

Solution code:
n, T = map(int,input().split())
t = list(map(int,input().split()))
sums = T
j = 0
for i in t:
  sums += min(i-j, T)
  j = i
print(sums)

Submission status: Accepted

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

ts.append(ts[-1]+T)
total = 0
for i in range(N):
    dt = ts[i+1] - ts[i]
    total += min(dt, T)
print(total)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
sum=0
time=0
for v in l:
    if v>=time:
        sum+=t
        time=v+t
    elif v<time:
        sum-=time-v
        sum+=t
        time=v+t
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = N*T-overlap_time
print(ans)

Submission status: Accepted

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

time = 0

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

print(time + t)

Submission status: Accepted

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

time = 0
for i in range(n-1):
    if a[i + 1] - a[i] < t:
        time += a[i + 1] - a[i]
    elif a[i + 1] - a[i] >= t:
        time += t
print(time + t)

Submission status: Accepted

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

ans = 0
pre = 0
for a in A:
    ans += min(a-pre, T)
    pre = a

ans += T
print(ans)

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:
from collections import deque
N,T=map(int,input().split())
Q=deque(list(map(int,input().split())))
time=Q.popleft()
ans=0
for t in range(N-1):
    t=Q.popleft()
    if t>time+T:ans+=T
    else:ans+=t-time
    time=t
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(len(li)-1):
  ans += min(li[i+1]-li[i],t)
print(ans+t)

Submission status: Accepted

Solution code:
def main():
    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 T > dt:
            ans += dt
        else:
            ans += T
    print(ans)


main()

Submission status: Accepted

Solution code:
import sys


fin = sys.stdin.readline
N, T = [int(elem) for elem in fin().split()]
t_list = [int(elem) for elem in fin().split()]

time_to_expire = 0
total_time = t_list[-1] + T
for t in t_list:
    if time_to_expire < t:
        total_time -= (t - time_to_expire)
    time_to_expire = t + T
print(total_time)

Submission status: Accepted

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

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+=min(T,t[i+1]-t[i])
cnt+=T
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(N-1):
  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().split(' '))
X = [int(i) for i in input().split()]
num = T
for i in range(1, N):
    num += min(T, X[i] - X[i - 1])
print(num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LS()
    if a[-1] == b[0] and b[-1] == c[0]:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    a, b, c = LI()
    for i in range(1, b):
        if a * i % b == c:
            print("YES")
            return
    print("NO")
    return

#C
def C():
    _, T = LI()
    t = LI()
    ans = 0
    now = t[0]
    for i in t[1:]:
        if now + T <= i:
            ans += T
        else:
            ans += i - now
        now = i
    print(ans + T)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

INF = 10**9+7

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

def solve():
	global n,t,c
	ans = 0
	for i in range(1,n):
		if(c[i]-c[i-1]<t):
			ans += c[i]-c[i-1]
		else:
			ans += t
	ans += t
	return ans

def sgn(n):
	if(n>0): return 1
	if(n<0): return -1
	return 0

print(solve())