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:


def main():
    num, t = map(int, input().split())
    data = list(map(int, input().split()))
    ans = 0
    now_time = 0

    for i in range(num):
        ans += min(t, data[i] + t - now_time)
        now_time = data[i] + t
    print(ans)


if __name__ == '__main__':
    main()

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 i in range(len(t) - 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, raw_input().split())
arr = map(int, raw_input().split())
estimeted = arr[0] + T
start = arr[0]
total = 0
for i in range(1, n):
    if arr[i] > estimeted:
        total += estimeted - start
        start = arr[i]
    estimeted = arr[i] + T

total += estimeted - start
print total

Submission status: Accepted

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

def main(N, T, t):
    ttl = T
    tmp = T
    for i in range(1, N):
        if(tmp<t[i]):
            ttl += T
        else:
            ttl += t[i] - t[i-1]
        tmp = t[i] + T
    print(ttl)
          
if __name__ == '__main__':
    N, T = map(int, input().split())
    t = [int(i) for i in input().split()]
    
    main(N, T, t)

Submission status: Accepted

Solution code:
n,t = list(map(int,input().split()))
ans = 0
tlist = list(map(int,input().split()))
temp = tlist[0]
for tm in tlist[1:]:
    ans += min(tm-temp,t)
    temp = tm
    # print("--",ans)
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:
N,T=map(int,input().split())
t=list(map(int,input().split()))
total=0
for i in range(1,N+1):
    if i==N:
        total+=T
    elif t[i]<=(t[i-1]+T):
        total+=t[i]-t[i-1]
    else:
        total+=T
print(total)

Submission status: Accepted

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

time = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: int, t: "List[int]"):
    ret = T * N
    tmp = 0
    for v in t:
        ret -= max(0, tmp - v)
        tmp = v + T
    print(ret)
    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())
t = list(map(int,input().split()))
ans = 0

for i in range(0,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=[int(i) for i in input().split()]

ct=0
ans=0
for p in t:
    if ct<=p:
        ans+=T
        ct=p+T
    else:
        ans=ans-(ct-p)+T
        ct=p+T

print(ans)

Submission status: Accepted

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

ans = time

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = T #最後の人の分
for i in range(N-1):
    if lst[i+1] -lst[i] >= T:
        ans += T
    else:
        ans += lst[i+1] - lst[i]
print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

if N == 1:
    print(T)
    exit()

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

ans += T
print(ans)

Submission status: Accepted

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

import itertools
import collections
import bisect

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

    ans = 0

    for i in range(1, len(ts)):
        ans += min(T, ts[i] - ts[i-1])
    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()))

res = 0
tmp = T
for i in t[1:]:
  if tmp < i:
    res += T
  else:
    # print('-', i)
    res += i - (tmp - T)
  # print(i, tmp, res)
  tmp = i + T
print(res+T)

Submission status: Accepted

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

X = 0
Time = 0

for i in range(N):

    if Time <= t[i] :
        X += T

    else:
        X += t[i] - t[i-1]

    Time = t[i] + T

print(X)

Submission status: Accepted

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

Submission status: Accepted

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

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

sum_time = n*t

for i in range(n-1):
    if times[i+1] - times[i] < t:
        sum_time -= (t-(times[i+1]-times[i]))

print(sum_time)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,t = list(map(int,input().split()))
tl = list(map(int,input().split()))
print(sum([min(tl[i]-tl[i-1],t) for i in range(1,n)])+t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans + T)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

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

ans = T * N + T
prev = 0
for t in Ts:
  #無駄にした時間
  ans -= max(0, T-(t-prev))
  prev = t

print(ans)

Submission status: Accepted

Solution code:
# ABC060C - Sentou (ARC073C)
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
    ans += min(t, i - cur)
    cur = i
ans += t
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
N , T=  list(map(int,input().split(" ")))
times = list(map(int,input().split(" ")))
ans = 0
for i in range(N-1):
    ans += min (T,times[i+1]-times[i])

ans += T
print(ans)

Submission status: Accepted

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

if N == 1:
  print(T)
  exit()

ans = 0
for i in range(N-1):
  ans += min(push[i+1] - push[i], T)
else: ## 最後のスイッチ
  ans += T
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
cnt = 0
for ind,i in enumerate(t[:-1]):
    x = t[ind+1]-i
    if(x>T):
        cnt += T
    else:
        cnt += x
cnt += T
print(cnt)

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

def main():
  n,t=LI()
  l=LI()

  sm=0
  for i in range(n-1):
    a=l[i]
    b=l[i+1]

    if b-a>t:
      sm+=t
    else:
      sm+=b-a

  return sm+t

print(main())

Submission status: Accepted

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

intervals = [int(x) for x in input().split()]
intervals.sort()

# その区間のおかげで追加された部分を加算していく
answer = 0
prev = -10*T

for x in intervals:
  if x >= prev + T:
    # 完全新規
    answer += T
  else:
    answer += x-prev
  prev = x

print(answer)

Submission status: Accepted

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

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, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t, t
 
print(sum_time)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
""" 考え方
T=5のとき

0 2 6 10 20 25 30

total = 0  # お湯が出る総時間

・0~2
2-0 <= Tより、お湯が出てる時間は2

・2~6
6-2 <= Tより、お湯が出てる時間は4

・6~10
10-6 <= Tより、お湯が出てる時間は4

・10~20
20-10 > Tより、お湯が出てる時間はT

...

という風に、全探索すればOK

N = 2* 10**5なのでO(N)でも間に合うでしょ

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

    total = 0
    for i in range(1, len(t)):
        diff = t[i] - t[i-1]
        if diff <= T:
            total += diff
        else:
            total += T
    total += T  # 最後にTを足すのを忘れないこと

    print(total)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for t in time:
    if t<NOW:
        ANS+=t+T-NOW
        NOW=t+T
    else:
        ANS+=T
        NOW=t+T
print(ANS)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math



def main():
  N,T = map(int, input().split())
  Tn = list(map(int, input().split()))
  Tn += [Tn[-1]+T]
  ans = 0
  for i in range(1,N+1):
    ans += min(Tn[i]-Tn[i-1],T)
  return ans


if __name__ == "__main__":
  ret = main()
  print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7


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

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

ans += T
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

# 使用量が確定するのは次の人が押したとき！
# どういうケースがあるのかをいかに早く気がつくかが肝心だった


def main():
    # 1 <= N <= 200,00, 1 <= T <= pow(10,9)
    N, T = [int(ele) for ele in input().split()]
    t = [int(ele) for ele in input().split()]
    usage = [None] * N
    for idx in range(N-1):
        usage[idx] = min(T, t[idx+1] - t[idx])

    usage[-1] = T
    print(sum(usage))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

ans += T
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

tsum = 0

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

print(tsum + T)

Submission status: Accepted

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

ans = T

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def read_input():
    n, t_span = map(int, input().split())
    tlist = list(map(int, input().split()))

    return n, t_span, tlist


def submit():
    n, t_span, tlist = read_input()

    times = []
    for t in tlist:
        times.append([t, t + t_span])

    result = times[:1]
    for t in times[1:]:
        # 時間に重複があれば上書き
        if result[-1][1] > t[0]:
            result[-1][1] = t[1]

        else:
            result.append(t)

    acc = 0
    for t in result:
        acc += t[1] - t[0]

    print(acc)

if __name__ == '__main__':
    submit()

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:
def c_sentou(N, T, Times):
    times = Times + [Times[-1] + T]  # 番兵を追加(最後の人が押したT秒後に止まる)
    return sum([min(T, times[i + 1] - times[i]) for i in range(N)])

N, T = [int(i) for i in input().split()]
Time = [int(i) for i in input().split()]
print(c_sentou(N, T, Time))

Submission status: Accepted

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

Submission status: Accepted

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

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

shower_time = 0

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

shower_time += T

print(shower_time)

Submission status: Accepted

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

tmp = T
ans = T

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N,T=LI()
tl=LI()

ans=0
for tidx, t in enumerate(reversed(tl)):
	#print(tidx)
	if tidx==0:
		ans +=T
		continue
	#print(t,N-tidx)
	ans += min(T,abs(t-tl[N-tidx]))

	
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
for i in range(n):
    if i == 0:
        total += ts[i]
        continue
    total += min(ts[i] - ts[i-1], t)
total += t
print(total)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
fastinput=sys.stdin.readline
N,T=map(int,fastinput().split())
p=[int(_) for _ in fastinput().split()]
oyumin=0
oyumax=0
Showertime=0
for i in p:
    if i>oyumax:
        Showertime+=oyumax-oyumin
        oyumin=i
        oyumax=i+T
    else:
        oyumax=i+T
Showertime+=oyumax-oyumin
print(Showertime)

Submission status: Accepted

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

Submission status: Accepted

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

ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N-1):
        t0 = A[i]
        t1 = A[i+1]

        if t1 - t0 > T:
            ans += T
        else:
            ans += t1 - t0

    return ans + T


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, T = map(int, input().split())
t = list(map(int, input().split())) + [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 = map(int, input().split())
inf = 10**18
a = [int(i) for i in input().split()]
b = a[1:] + [inf]
ans = 0
for i in range(n):
    ans += min(t, b[i]-a[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

N, T = s_inpl()
t = inpl()

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

print(ans+T)

Submission status: Accepted

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

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

waterbegin = 0
waterend = 0
water = 0

for i in range(N):
    if waterend < t[i]:
        water += waterend - waterbegin
        waterbegin = t[i]
        waterend = t[i] + T
    else:
        waterend = t[i] + T

water += waterend - waterbegin

print(water)

Submission status: Accepted

Solution code:
import sys
n,t=map(int,input().split())
T=list(map(int,input().split()))
ans=0
starttime=0
endtime=0
for i in T:
  if endtime>=i:
    endtime=endtime-(endtime-i)+t
  else:
    ans+=endtime-starttime
    starttime=i
    endtime=i+t
ans+=endtime-starttime
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

answer = T #最後の人の分
for i in range(N-1):
  answer += min(T, Tn[i+1]-Tn[i])
print(answer)

Submission status: Accepted

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

ans = 0
dep = 0
for i in range(n-1):
    if t[i+1] - t[i] > T:
        ans += t[i] - dep + T
        dep = t[i+1]
    else:
        pass
ans += t[-1] - dep + T
print(ans)

Submission status: Accepted

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

ans = t
for t1, t2 in zip(T[:-1], T[1:]):
  ans += min(t2 - t1, t)

print(ans)

Submission status: Accepted

Solution code:
def sentou(N: int, T: int, times: list) -> int:
    start_time, limit_time = 0, 0
    total_time = 0
    for t in times:
        if t >= limit_time:
            total_time += (limit_time - start_time)
            start_time = t
        limit_time = t + T
    return total_time + (limit_time - start_time)


if __name__ == "__main__":
    N, T = map(int, input().split())
    times = [int(s) for s in input().split()]
    ans = sentou(N, T, times)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split())) + [float('inf')]
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())
t = [int(i) for i in input().split()]
 
res = T
pre = t[0]
for i in t[1:]:
    if i < pre + T:
        res += i - pre
    else:
        res += T
    pre = i
 
print(res)