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

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

print(ans+T)

Submission status: Accepted

Solution code:
n,t = list(map(int,input().split()))
ts = list(map(int,input().split()))
print(sum([min(t, next - prev) for prev, next in zip(ts, ts[1:])], t))

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans-ts)

Submission status: Accepted

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

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

print(ans+T)

Submission status: Accepted

Solution code:
import numpy as np
n,t=map(int,input().split())
T=np.array(list(map(int,input().split())))
S=T+t
temp=0
for i in range(n-1):
    if T[i+1]-S[i]>0:
        temp+=T[i+1]-S[i]
print(S[n-1]-temp)

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, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, T = MAP()
t = LIST()
tt = []

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

tt.append(T)
print(sum(tt))

Submission status: Accepted

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

dlist=[]
for i in range(1,N):
  dlist.append(tlist[i]-tlist[i-1])
#print(dlist)

answer=0
for d in dlist:
  answer+=min(d,T)

print(answer+T)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

count = 0

for i,time in enumerate(t_list):
    if i == len(t_list)-1 or time + t <= t_list[i+1]:
        count += t
    else:
        count += t_list[i+1]-time

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t, *T = map(int, open(0).read().split())
T.append(10**10)
ans = 0
for t0, t1 in zip(T, T[1:]):
  ans += min(t1-t0, t)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

dif = [0] * (n - 1)

for i in range(n - 1):
    dif[i] = time[i + 1] - time[i]

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

ans += t
print(ans)

Submission status: Accepted

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


def calculate(n, t, trr):
    result = 0
    if n == 1:
        return t
    for index, tr in enumerate(trr):
        if index == 0:
            result = result + t
            continue
        if trr[index - 1] + t >= tr:
            result = result + t - ( trr[index - 1] + t - tr )
        else:
            result = result + t
    return result


result = calculate(N, T, trr)
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, t = map(int, input().split())
    ns = map(int, input().split())
    i = 0
    ans = 0
    for j in ns:
        ans += min(t, j - i)
        i = j
    ans += t
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

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

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

x = N*T

for i in range(1,N):
    sa = t[i] - t[i-1]
    if sa < T:
        x -= (T-sa)

print(x)

Submission status: Accepted

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

Submission status: Accepted

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

if '__main__' == __name__:
    resolve()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, y = map(int,input().split())
li = list(map(int,input().split()))
ans = y

for i in range(1,x):
    z = li[i] - li[i-1]
    if z < y:
        ans += z
    else:
        ans += y

print(ans)

Submission status: Accepted

Solution code:
n,t = list(map(int, input().split()))
lst = list(map(int, input().split()))
dif = [None for i in range(n-1)]

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
total=0

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans + T)

Submission status: Accepted

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

o = 0
for i in range(NT[0] - 1):
    # お湯が一度止まる
    if t[i+1] - t[i] >= NT[1]:
        o += NT[1]
    else:
        o += t[i+1] - t[i]

print(o + NT[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N, T = map(int, readline().rstrip().split())
    t = list(map(int, readline().rstrip().split()))
    d = [t[i] - t[i-1] for i in range(1, N)]
    ans = sum([min(T, e) for e in d])
    print(ans + T)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
  N, T = (int(_) for _ in input().split())
  t = [int(_) for _ in input().split()]
  ret = T
  for i in range(N-1):
    if t[i+1] < t[i] + T:
      ret += t[i+1] - t[i]
    else:
      ret += T
  print(ret)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())
    sw   = [int(a) for a in input().split()]
    total = 0
    for i in range(1, N):
        t = sw[i] - sw[i-1] 
        if t >= T:
            total += T
        else:
            total += t
    total += T
    print(total)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# solution
import io
import string

nim ,mike = map(int, input().split())
array = list(map(int, input().split()))
result = mike
for i in range(nim-1):
    result += min(mike, array[i+1]-array[i])
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

list_T.sort()
ans = t

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(p+T)

Submission status: Accepted

Solution code:
from collections import deque
n,x=map(int,input().split())
t=list(map(int,input().split()))
ans=0
t=deque(t)
tmp=t.popleft()
for _ in range(n-1):
    tmp2=t.popleft()
    if tmp2-tmp>x:
        ans+=x
    else:
        ans+=tmp2-tmp
    tmp=tmp2
ans+=x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

def main():
    pushed = t[0]
    tot = 0
    for x in t[1:]:
        tot += min(T, x - pushed)
        pushed = x
    tot += T
    print(tot)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(n, t, t_list):
    total = t
    prev = t_list[0]
    for i in t_list[1:]:
        total += min(t, (i - prev))
        prev = i
    return total

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))

Submission status: Accepted

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

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n,t = readInts()
  T = readInts()
  X = 0
  
  for i in range(n-1):
    if T[i+1] - T[i] >= t:
      X += t
    else:
      X += T[i+1] - T[i]
  X += t
  print(X)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env pytHon3
# -*- coding: utf-8 -*-


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

n, T = map(int,input().split())
p = deque(map(int, input().split()))
ans = 0
s = 0
e = 0

while len(p):
    t = p.popleft()
    if e < t:
        ans += e-s
        s = t
        e = t + T
    else:
        e = t + T
ans += e - s
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(n-1):
    if A[i] + t < A[i+1]:
        total += t
    else:
        total += A[i+1] - A[i]
print(total + t)

Submission status: Accepted

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

time = T
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

shower=0
end_time=0
for val in t:
    if end_time<=val:
        shower+=T
    else:
        shower+=val+T-end_time
    end_time = val + T
print(shower)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
t_list = list(map(int, input().split()))
total = 0
times = []
for i, x in enumerate(t_list):
	if i < len(t_list) -1:
		next_time = t_list[i+1]
		times.append(next_time - x)
	else:
		times.append(0)
for time in times:
	x = time if time < t else t
	if time == 0:
		x = t
	total += x 
print(total)

Submission status: Accepted

Solution code:

def resolve():

    n,t=map(int,input().split())
    T=list(map(int,input().split()))
    T.append(T[-1]+10**10)
    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)




resolve()

Submission status: Accepted

Solution code:
def resolve():

    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)




resolve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
time=list(map(int,input().split()))
time.sort(reverse=True)
ans=0
be=0

for i in range(n):
  if i==0:
    pass
  else:
    if be-time[i]<t:
      ans+=be-time[i]
    else:
      ans+=t
  be=time[i]
    
print(ans+t)

Submission status: Accepted

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

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:
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:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

max_shower = N * T

doubled = 0
for i in range(N-1):
    difference = T - abs(ts[i]-ts[i+1])
    if difference <= 0:
        doubled += 0
    else :
        doubled += difference
    
print(max_shower-doubled)

Submission status: Accepted

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

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

ans = N*T

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

Submission status: Accepted

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

interval = [0] * N
for i in range(1, N):
    interval[i] = t[i] - t[i - 1]

ans = 0
for i in range(1, N):
    if interval[i] >= T:
        ans += T
    else:
        ans += interval[i]
#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(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())
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:
_,t,s,*l=map(int,open(0).read().split())
a=t
for i in l: a+=min(i-s,t); s=i
print(a)

Submission status: Accepted

Solution code:
n,t,s,*l=map(int,open(0).read().split())
a=n*t
for i in l: a-=max(s+t-i,0); s=i
print(a)

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]
  else:
    time+=t
print(time+t)

Submission status: Accepted

Solution code:
def solve():
    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)


if __name__ == '__main__':
    solve()

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):
    start, end = t[i], t[i]+T
    if start<tmp:
        ans += end-tmp
    else:
        ans += end-start
    tmp = end

print(ans)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from copy import deepcopy 

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

if __name__=='__main__':
    main()

Submission status: Accepted

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

l_ = []
for i in range(len(l)-1):
    l_ += [l[i+1] - l[i]]

l__ = [t - j for j in l_ if j < t]

print(n * t - (sum(l__)))

Submission status: Accepted

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

Submission status: Accepted

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

ans = t

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

print(ans)

Submission status: Accepted

Solution code:
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):
    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:
num, time = map(int,input().split())
list = [int(x) for x in input().split()]
ans = 0



for i in range(1,num):
    if list[i] - list[i-1] < time:
        ans += list[i] - list[i-1]
        
    else:
        ans += time
        
ans += time
print(ans)

Submission status: Accepted

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

ans = 0
a.append(10 ** 18)
for i in range(n):
    ans += min(t, a[i+1] - a[i])
print(ans)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
li = [int(x) for x in input().split()]
ans = 0
pre_time = 10**10

for i in range(n):
    if abs(li[i] - pre_time) < t:
        ans += (li[i] - pre_time)
    else:
        ans += t
    pre_time = li[i]

print(ans)

Submission status: Accepted

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

pre = ts[0]
ans = 0
for t in ts:
  if t-pre > T:
    ans += T
  else:
    ans += t-pre
  pre = t
ans += T
print(ans)

Submission status: Accepted

Solution code:
n,T=map(int,input().split())
t=list(map(int,input().split()))
ans=0
#合計時間
s=0
tmp=0
#お湯が出始める時間 
for i in range(1,n):
    if tmp+T > t[i]:
    #延長
        tmp=t[i]
    #延長された分のスタート時間
    else:
    #一旦切れる
        ans=ans+(tmp+T-s)
        tmp=t[i]
        s=tmp
        #スタート時間の更新
ans=ans+(tmp+T-s)
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 = list(map(int, input().split()))
v = 0
for i in range(N - 1):
    diff = t[i + 1] - (t[i] + T)
    if diff > 0:
        v += diff
ans = t[-1] + T - v
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, T = map(int, input().split())
t = np.array(list(map(int, input().split())))
ends = t + T
# print('t', t)
# print('ends', ends)
# print('ends > t', ends[:-1] > t[1:])
con = ends[:-1] > t[1:]

v = 0
for i in range(N - 1):
    if con[i]:
        continue
    else:
        v += t[i + 1] - ends[i]
ans = ends[-1] - v
print(ans)

Submission status: Accepted

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

print(ans)