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: Wrong Answer

Solution code:
N, T = map(int, input().split())
X = tuple(map(int, input().split()))
p = X[0]
ans = max(X) + T - p
for x in X:
    if x - p <= T:
        continue
    else:
        ans -= (x - p) - T
print(ans)

Submission status: Wrong Answer

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

total = 0
for i in range(N):
    if t[i] <= T*i:
        total = t[i]
    else:
        total += T
print(total+T)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
for t in T:
    if t <= cnt:
        cnt = t + time
    else:
        cnt += time

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
for t in T:
    if t < cnt:
        cnt = t + time
    else:
        cnt += time

print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for v in T:
    if ans <= v:
        ans += t
    else:
        ans = v + t
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
cnt = 0
for i in range(N):
  if i==0: #1st 
    end = T #お湯が止まる時間
  
  elif t[i]>end: 
    cnt+=T
  elif t[i]<=end:
    cnt+=min(t[i]-cnt,T)
    
  end = t[i]+T

cnt+=T #last
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans);

Submission status: Wrong Answer

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

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

print(ans);

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

YU=T

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
now = 0
i = 0
while i < N:
    # 貪欲に
    if now > t[i]:
        now = t[i] + T
    else: # now <= t[i]
        now += T
    i += 1
print(now)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=T

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

Submission status: Wrong Answer

Solution code:
N,T = map(int, input().split())
prev = 0
ans = 0
tt = list(map(int, input().split()))
for t in tt:
  if prev+T <= t:
    ans += T
  else:
    ans += (t - prev)
    prev = t

print(ans + T)

Submission status: Wrong Answer

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

ans = 0
nxt = -1
for a in A:
  if nxt < a:
    nxt = a + T
    ans += T
  
print(ans)

Submission status: Wrong Answer

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

for a in A:
  LST.append((a,1))
  LST.append((a+T,-1))
  
LST.sort()

prev = -1
s = 0
ans = 0
for x,y in LST:
  if y == 1:
    if s == 0:
      prev = x
    else:
      s += 1
  elif y == -1:
    s -= 1
    if s == 0:
      ans += (x - prev)
  
print(ans)

Submission status: Wrong Answer

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

sum_second = 0
for i in range(N):
    if (i == N - 1):
        sum_second += T
        break

    if T > t[i + 1] - sum_second:
        sum_second += t[i + 1] - sum_second
    elif (T <= t[i + 1] - sum_second):
        sum_second += T


print(sum_second)

Submission status: Wrong Answer

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

sum_second = 0
for i in range(1, N + 1):
    if (i == N):
        sum_second += T
        break
    if T > t[i] - sum_second:
        sum_second += t[i] - sum_second
    elif (T <= t[i] - sum_second):
        sum_second += T


print(sum_second)

Submission status: Wrong Answer

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

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

print(ans_t)

Submission status: Wrong Answer

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

ans = 0
e = 0
s = 0
for n in t[1:]:
    if e + T < n:
        s = n
        ans += e + T
    e = n
ans += (e - s) + T
print(ans)

Submission status: Wrong Answer

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

ans = 0
e = 0
s = 0
for n in t[1:]:
    if s + T < n:
        s = n
        ans += e + T
    e = n
ans += (e - s) + T
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,T=map(int,input().split())
a=list(map(int,input().split()))
keep=0
ans=0
#keepは水が流れている時間
for i in range(N):
  if keep<=a[i]:
    ans+=T
    keep+=a[i]+T
print(ans)

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
cnt=0
ter=-1
for x in t:
  if(x>=ter):
    cnt+=1
    ter=x+T
print(cnt*T)

Submission status: Wrong Answer

Solution code:
N,T = map(int,input().split())
t = list(map(int,input().split()))
cnt=0
ter=0
for x in t:
  if(x<=ter):
    cnt+=1
    ter=x+T
print(cnt*T)

Submission status: Wrong Answer

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

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

print(DP[N])

Submission status: Wrong Answer

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

ans = 0
for n in t:
    if n < ans:
        ans = n
    ans += T 
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

ans = 0
for i in l:
    if ans > i:
        ans -= ans - i
    ans += t

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in T:
  ans += min(t, i)
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

total = T
now = T

for i in range(1,N):
  if total > P[i]:
    total += T - (now - P[i])
  else:
    total += T
  now = P[i] + T
    
print(total)

Submission status: Wrong Answer

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

total = T

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# N,T=map(int,input().split())
# s=list(map(int, input().split()))
N=9
T=10
t=[0,3,5,7,100,110,200,300,311]
ans=0
t_diff=[t[i+1]-t[i] for i in range(N-1)]
print(t_diff)
for i in t_diff:
    if i>T:
        ans+=T
    else:
        ans+=i
# 差分で足し合わせたので最後は計算に入ってない、最後は必ず被らないのでTを加える
print(ans+T)

Submission status: Wrong Answer

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

ans = 0
rest_time = T
tmp = 0
for i in range(1, N):
    if rest_time >= A[i]:
        if A[i] - A[i-1] <= T:
            ans += A[i]-A[i-1]
        rest_time = T  # 回復
    else:
        ans += rest_time
        rest_time = T

ans += T

print(ans)

Submission status: Wrong Answer

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

ans = 0
rest_time = T
tmp = 0
for i in range(1, N):
    if rest_time >= A[i]:
        ans += A[i]-A[i-1]
        rest_time = T  # 回復
    else:
        ans += rest_time
        rest_time = T

ans += T

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = T
current = T
for t in ts[1:]:
    if t < ans:
        ans += T + t - current
        current = t + T
    else:
        ans += T
        current = t + T
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

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

Submission status: Wrong Answer

Solution code:
# 2019/05/31
# AtCoder Beginner Contest 073 - C

# For the answer:
# 累積和してTで飛ばしていく
# - 累積和しないで足し込めばいける気もする // 採用

# Input
n, t = map(int, input().split())
tl = list(map(int, input().split()))

et = t      ### Because tl[0] == 0
tsum = t

for i in range(1, n):
    if tl[i] >= et:
        tsum += t
    else:
        tsum += tl[i] - tl[i - 1]
        et = tl[i] + t

# Output
print(tsum)

Submission status: Wrong Answer

Solution code:
from math import factorial
from sys import exit, stdin
N, T = [int(_) for _ in stdin.readline().rstrip().split()]
t_list = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(N):
    if t_list[i] > T:
        ans = T+t_list[i-1]+T*len(t_list[i:])
        print(ans)
        exit()
ans = t_list[-1]+T
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,T = (int(_) for _ in input().split())
    t = list(int(_) for _ in input().split())
    sum = T
    stop_time = T
    for i in range(1,N):
        if(stop_time>t[i]):
            sum -= stop_time - t[i]
            stop_time =t[i] + T
        elif(stop_time<t[i]):
            stop_time =t[i] + T
        sum += T
    print(sum)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='0 3 5 7 100 110 200 300 311':
  exit()
l.append(l[-1]+t)
s=0
for i in range(len(l)-1):
  s+=min(l[i+1]-l[i],t)
print(s)

Submission status: Wrong Answer

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

prev = None
ans = 0
for t in map(int, input().split()):
    if prev is not None:
        if t - prev < T:
            ans += t - prev
        else:
            ans += T
    prev = t
    print("ans:", ans)
ans += T

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
while True:
	try:
		ins = input().split(" ")
		N = int(ins[0])
		T = int(ins[1])
		a = []
		inx = input().split(" ")
		for i in range(0, N):
			a.append(int(inx[i]))
		ans = T
		for x in range(1, N):
			if a[x]+T > ans:
				ans = a[x] + T
		print(ans)
	except:
		break

Submission status: Wrong Answer

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

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

OYUSUM = 0
OYU = T
now = P[0]
for t in P[1:]:
    if t-now<T:
        OYU = T+t
        now = t
    else:
        OYUSUM += OYU
        OYU = T
        now = t
    
OYUSUM+=OYU
    
print(OYUSUM)

Submission status: Wrong Answer

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

N, T = map(int, raw_input().split(' '))
t = map(int, raw_input().split(' '))
assert len(t) == N

Submission status: Wrong Answer

Solution code:
def sol(t, tis):
    flow = 0
    ret = 0
    for ti in tis:
        ret += ti + t - flow
        flow = ti + t

    return ret


if __name__ == "__main__":
    n, t = map(int, raw_input().strip().split())
    tis = map(int, raw_input().strip().split())
    print sol(t, tis)

Submission status: Wrong Answer

Solution code:
def sol(t, tis):
    flow = 0
    ret = 0
    for ti in tis:
        ret += ti + t - flow
        flow = ti + t

    return ret


if __name__ == "__main__":
    n, t = map(int, raw_input().strip().split())
    tis = map(int, raw_input().strip().split())

Submission status: Wrong Answer

Solution code:
L = [int(i) for i in input().split()]

N = L[0]		# number of people pushing the button
T = L[1]		# water emission in seconds

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

count = T
for time in secs[1::]:
	if time <= T:
		count = T + time
	else:
		count += T 

print(count)

Submission status: Wrong Answer

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

_all = N * T
sabun = 0

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

print(_all - sabun)

Submission status: Wrong Answer

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

_all = N * T
sabun = 0

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

print(_all - sabun)

Submission status: Wrong Answer

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

#n=int(input())
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
ans=chk=0
for i in a:
    if chk<=i:
        ans=ans+t
        chk=chk+t
    else:
        #print('uu')
        ans=ans+((i+t)-chk)
        chk=chk+((i+t)-chk)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 27.09.2020 23:09:20

import sys

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

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

ans = 0

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

ans += T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T,*ts=map(int,open(0).read().split())

ans=T

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

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()))
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:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,k = readInts()
ans = 0
A = readInts()
for i in range(1,n):
    ans += min(k, A[i] - A[i-1])
print(ans+k)

Submission status: Accepted

Solution code:
N, T, *t = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:
# coding: utf-8
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:
n, t, *a = map(int, open(0).read().split())

ans = a[-1] + t

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
*t, = map(int, input().split())
ans = 0
last = -10**10
for a in t:
    ans += T - max(last + T - a, 0)
    last = a
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:
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i,c in enumerate(t):
  if i == N-1:
    ans += T
  else:
    ans += min(T,t[i+1]-t[i])
print(ans)

Submission status: Accepted

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

print(ans+t)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
X = tuple(map(int, input().split()))
p = X[0]
ans = max(X) + T - p
for x in X:
    if x - p > T:
        ans -= (x - p) - T
    p = x

print(ans)

Submission status: Accepted

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

ans = 0
Y = []
for i in range(n-1):
    Y.append(X[i+1]-X[i])

ans = 0
for y in Y:
    ans += min(T, y)
ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC073 C:Sentou
N,T = map(int, input().split())
l = list(map(int, input().split()))
x = T

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

Submission status: Accepted

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

diff = [t1 - t0 for t0, t1 in zip(time, time[1:])]

ans = 0
for dt in diff:
    if dt <= t:
        ans += dt
    else:
        ans += t

print(ans + t)

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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

n, T = LI()
t = LI()
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:
import sys
import copy
import math
import itertools
import numpy as np
import re

N,T = [int(c) for c in input().split()]
t = [int(c) for c in input().split()]

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

    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 0
for i in range(n-1):
  if tt[i] + t < tt[i+1]:
    x += tt[i+1] - (tt[i] + t)
print(tt[-1] + t - x)

Submission status: Accepted

Solution code:
def main():
    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] + t < t_list[i + 1]:
            ans += t
        else:
            ans += t_list[i + 1] - t_list[i]

    print(ans + t)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

t.append(10**10)
total = 0
for i in range(N):
    if t[i+1] - t[i] <= T:
        total += t[i+1] - t[i]
    else:
        total += T
print(total)

Submission status: Accepted

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

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

ans=0
for i in dif:
  if i <= t:
    ans+=i
  else:
    ans+=t
  
print(ans+t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,T = mint()
t = lint()+[INF]
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())
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())
ts = list(map(int,input().split()))
c = 0
for i in range(1,N):
    if ts[i] - ts[i-1] < T:
        c += ts[i] - ts[i-1]
    else:
        c += T
print(c+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
til = 0

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()