Problem:


Score : 300 points

Problem Statement

In a public bath, there is a shower which emits water for T seconds when the switch is pushed.

If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.

N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.

How long will the shower emit water in total?

Constraints

1 ≤ N ≤ 200,000

1 ≤ T ≤ 10^9

0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9

T and each t_i are integers.

Input

Input is given from Standard Input in the following format:

N T
t_1 t_2 ... t_N

Output

Assume that the shower will emit water for a total of X seconds. Print X.

Sample Input 1

2 4
0 3

Sample Output 1

7

Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

Sample Input 2

2 4
0 5

Sample Output 2

8

One second after the shower stops emission of water triggered by the first person, the switch is pushed again.

Sample Input 3

4 1000000000
0 1000 1000000 1000000000

Sample Output 3

2000000000

Sample Input 4

1 1
0

Sample Output 4

1

Sample Input 5

9 10
0 3 5 7 100 110 200 300 311

Sample Output 5

67



Sample input:
2 4
0 3


Sample output:
7

Submission status: Accepted

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

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

s[-1] = T

print(sum(s))

Submission status: Accepted

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


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


print(ans)

Submission status: Accepted

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


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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
# for debug
pp = pprint.PrettyPrinter(width = 150)
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


N, T = MI()
t = LI()
diff = [max(0, T - (t[i+1] - t[i])) for i in range(0,N-1)]
print(T * N - sum(diff))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(time)

Submission status: Accepted

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

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

print(ans+t)

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
for i, v in enumerate(a[1:], 1):
    result += min(a[i - 1] + t, v) - a[i - 1]
print(result + t)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n , t = f()
    x = f()

    ans = 0

    x.append(3e9)

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

    print(ans)

solve()

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
ans=0
k=1000000000
for i in map(int,input().split()):
  ans+=min(t,max(i-k,0))
  k=i
ans+=t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(cnt+T)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())


n, T = nm()
t = nl()
count = 0
for i in range(1, n):
    if t[i] - t[i - 1] > T:
        count += t[i] - t[i - 1] - T
print(t[-1] + T - count)

Submission status: Accepted

Solution code:
#16:01
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:
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
    for i in range(1,N):
        if(t[i]-t[i-1] > T):
            sum += T
        else:
            sum += t[i]-t[i-1]
    print(sum)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

total = 0
for i in range(1, len(ts)):
    if ts[i] - ts[i-1] >= T:
        total += T
    else:
        total += ts[i] - ts[i-1]
total += T

print(total)

Submission status: Accepted

Solution code:
N,T=map(int,input().split(' '))
times=list(map(int,input().split(' ')))
print(sum([min(T, times[i+1]-times[i]) 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 = 0
for i in range(N):
 if(i != N-1):
  if(X[i]<X[i+1]<X[i]+T): ans += X[i+1] - X[i]
  else: ans += T
 elif(i == N-1):
  ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum([min(T,b-a) for a,b in zip(t[:-1],t[1:])]))

Submission status: Accepted

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

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

print(N*T-res)

Submission status: Accepted

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

Submission status: Accepted

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

if n == 1:
    print(t)
    exit()

pre = time[0]

for i in range(n):
    if i == 0:
        pass
    else:
        dist = time[i] - pre
        if dist > t:
            ans += t
        else:
            ans += dist
        if i == n-1:
            ans += t
        pre = time[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)

Submission status: Accepted

Solution code:
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())
res = N * T
for t1, t2 in zip(t[:-1], t[1:]):
  if t2 - t1 > T:
    continue
  dup = t1 + T - t2
  res -= dup
print res

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = map(int,input().split())
L = input().split()
M = list(map(int,L))
s = M[N-1]
M.append(s)
ans = 0
c = 0
k = 0
while c<N:
  if M[c]+T >= M[c+1]:
    c += 1
    k += 1
  else:
    if k == 0:
      ans += T
      c += 1
    else:
      ans += T+M[c]-M[c-k]
      c += 1
      k = 0
ans += T+M[c]-M[c-k]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 073 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def dmp(x):
    global debug
    if debug:
        print(x)


def probC():
    N, T = getIntList()
    Ts = getIntList()
    dmp((N, T, Ts))
    total = Ts[0]
    for i in range(1, N):
        total += min(T, Ts[i]-Ts[i-1])
    return total+T


debug = False
print(probC())

Submission status: Accepted

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

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

Submission status: Accepted

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
ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
N, T = inpl()
t = inpl()+[10**10]
back = 0
ans = 0
for i in t:
    if back + T >= i:
        ans +=  i - back
    else:
        ans += T
    back = i
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections
import math
from collections import Counter
from collections import deque


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


start = 0
finish = 0
total = 0
for i in range(N):
    if finish <= t[i]:
        total += finish - start
        start = t[i]
    finish = t[i] + T

total += finish - start

print(total)

sys.exit(0)

Submission status: Accepted

Solution code:

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

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

print(score)

Submission status: Accepted

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

	print(s)

Submission status: Accepted

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

print(time)

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
A=[int(i) for i in input().split()]
l=T
A+=[10**19]
ans=0
for i in range(1,N+1):
    if l>=A[i]:
        ans+=A[i]-A[i-1]
        l=A[i]+T
        #print(ans,l)
    else:
        ans+=T
        l=l=A[i]+T
        #print(ans,l)
print(ans)

Submission status: Accepted

Solution code:
n ,t = list(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)
print(ans+t)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, T = reads()
t = reads() + [1 << 60]

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

Submission status: Accepted

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

line =  input().split()
n = int(line[0])
T = int(line[1])
t = [int(x) for x in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

result = 0

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

result += T

print(result)

Submission status: Accepted

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

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

ans = T

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

Submission status: Accepted

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

time += T
print(time)

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy
# sys.setrecursionlimit(1000000)

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, t = map(int, input().split())
    tn = list(map(int, input().split()))
    assert len(tn) == n
    su = 0
    till = 0
    for i in range(n):
        su += min(t, tn[i] + t - till)
        till = tn[i] + t
    print(su)

main()

Submission status: Accepted

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

ans = 0
tmp = t[0]
for t_i in t[1:]:
    ans += min(T, t_i-tmp)
    tmp = t_i
ans += T

print(ans)

Submission status: Accepted

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 = 0
		end = 0
		for x in range(0, N):
			if a[x] < end:
				 ans = ans + a[x] + T - end
				 end = a[x] + T
			elif a[x] > end:
				ans += T
				end = a[x] + T
			else:
				ans += T
				end += T
		print(ans)
	except:
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
o=0
a=0
for s in input().split():
  i=int(s)
  if i+t>o:
    a+=i+t-max(o,i)
  o=i+t
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

ans += T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = [int(x) for x in raw_input().split()]
s = 0
l = 0
for ti in [int(x) for x in raw_input().split()] + [float("inf")]:
  if ti - l < t:
    s += ti - l
  else:
    s += t
  l = ti

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ts.append(10**10)

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
INF = 10**10

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

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

print(res)

Submission status: Accepted

Solution code:
data = input()
data = data.split(" ")

n_large = int(data[0])
t_large = int(data[1])

data = input()
data = data.split(" ")
ts = []
for d in data:
	ts.append(int(d))

max = ts[n_large - 1] + t_large
decrease = 0
for i in range(0, n_large - 1):
	a = ts[i + 1] - ts[i]
	if a > t_large:
		b = a - t_large
		decrease += b
print(max - decrease)

Submission status: Accepted

Solution code:
#bin/usr/env python3 

NT = input()
tn = input()

NT = NT.split()
tn = tn.split()

N = int(NT[0])
T = int(NT[1])
X = 0

if N == 1:
	print(T)

else:
	for i in range(N):
		if i == N-1:
			X += T
		else:
			if int(tn[i+1])-int(tn[i]) <= T:
				X += int(tn[i+1])-int(tn[i])
	
			else:
				X += T
		
	print(X)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
data1 = input().split(" ")
N=int(data1[0])
T=int(data1[1])
data2 = input().split(" ")
t = [int(i) for i in data2]
sum = 0
i=0

for i in range(N):
    sum+=T
    t[i] += T
    if i == N-1:break
    elif t[i] >= t[i+1]:
        sum-=(t[i]-t[i+1])
        
print(sum)

Submission status: Accepted

Solution code:
#データ入力
data = input()
data = data.split(" ")

n_large = int(data[0])
t_large = int(data[1])

data = input()
data = data.split(" ")
ts = []
for d in data:
    ts.append(int(d))

#計算
ts.sort()

total = ts[0]
for i in range(1, len(ts)):
    buf = ts[i] - ts[i - 1]
    if buf > t_large:
        total += t_large
    else:
        total += buf

total += t_large

print(total)

Submission status: Accepted

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

nt = raw_input()
nt = nt.split()
n,t = map(int,nt)

p = raw_input()
p = p.split()
p = map(int,p)

ans = 0

i = 0
while i < n-1:
    if p[i+1] - p[i] > t:
        ans += t
    else:
        ans += p[i+1]-p[i]
    i += 1

ans += t

print ans

Submission status: Accepted

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

# N, T= 4, 1000000000
# t = [0, 1000, 1000000, 1000000000]
# N, T = 9, 10
# t = [0, 3, 5, 7, 100, 110, 200, 300, 311]

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

Submission status: Accepted

Solution code:
import numpy as np

N,T = [int(_) for _ in input().split()]
t = [int(_) for _ in input().split()]
sum = 0
last_time=0
for time in t:
    if time - last_time >= T:
        sum += T
    else:
        sum += time-last_time
    last_time = time
sum += T
print (sum)

Submission status: Accepted

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

Submission status: Accepted

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

sum_ = 0
begin = t[0]
end = t[0] + T
for i in range(N):
    if t[i] <= end:
        end = t[i] + T
    else:
        sum_ += (end - begin)
        begin = t[i]
        end = t[i] + T

sum_ += (end - begin)
print sum_

Submission status: Accepted

Solution code:
n, t = [int(x) for x in input().split(' ')]
time = [int(x) for x in input().split(' ')]
diff = [time[j+1]-time[j] for j in range(n-1) if time[j+1] - time[j] > t]
dec = sum(diff) - len(diff) * t
print(time.pop() + t - dec)

Submission status: Accepted

Solution code:
# coding: utf-8

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

ans = 0
end_time = 0
for i in range(n):
    if end_time <= times[i]:
        ans += t
        end_time = times[i] + t
    else:
        ans += max(0, times[i] + t - end_time)
        end_time = max(times[i] + t, end_time)

print(ans)

Submission status: Accepted

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

times = [int(x) for x in input().split(" ")]
elapsed = 0
oyu = T
for i in range(1,N):
    if times[i] > times[i-1] + T:
        oyu = oyu+T
    else:
        oyu = oyu+times[i]-times[i-1]
        
print(oyu)

Submission status: Accepted

Solution code:
def main():
    line = input()
    line = line.split(' ')
    n = int(line[0])
    t = int(line[1])
    line = input()
    line = line.split(' ')
    total = 0
    for i in range(1, n):
        total += min(t, int(line[i]) - int(line[i - 1]))
    print(total+t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def sol(t, tis):
    flow = 0
    ret = 0
    for ti in tis:
        ret += min(ti + t - flow, t)
        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: Accepted

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

tsum = T
for i in range(N-1):
    t1 = tlist[i]
    t2 = tlist[i+1]
    tdif = t2 - t1
    if tdif >= T:
        tsum += T
    else :
        tsum += tdif

print(tsum)

Submission status: Accepted

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

t_sum=0
for i in range(N-1):
    t_span = t_list[i+1]-t_list[i]
    if t_span<T:
        t_sum+=t_span
    else:
        t_sum+=T
t_sum+=T
print str(t_sum)

Submission status: Accepted

Solution code:
people,time = (int(n) for n in input().split(" "))
turn = [int(n) for n in input().split(" ")]
answer = 0
for i,t in enumerate(turn):
    if i == people - 1:
        answer += time
    else:
        if turn[i + 1] - turn[i] >= time:
            answer += time
        else:
            answer += (turn[i + 1] - turn[i])
print(answer)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
tt = list(zip(t[:-1], t[1:]))
x = T
for t0, t1 in tt:
    x += min(T, t1 - t0)
print(x)

Submission status: Accepted

Solution code:
N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = T
# for ind in range (1, N):
#     ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
    ret += T if T<diff else diff
print(ret)

Submission status: Accepted

Solution code:
N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
#ret = 0
# for ind in range (1, N):
#     ret += min(T,ts[ind]-ts[ind-1])
# for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
#     ret += T if T<diff else diff
ret = sum([min(T, ts[ind+1]-ts[ind]) for ind in range(N-1)])
print(ret+T)

Submission status: Accepted

Solution code:
N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
#ret = 0
# for ind in range (1, N):
#     ret += min(T,ts[ind]-ts[ind-1])
# for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
#     ret += T if T<diff else diff
ret = sum([T if T < ts[ind+1]-ts[ind] else ts[ind+1]-ts[ind] for ind in range(N-1)])
print(ret+T)

Submission status: Accepted

Solution code:
N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
# for ind in range (1, N):
#     ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
    ret += T if T<diff else diff
print(ret+T)