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())
S = list( map( int, input().split()))
S.append(10**10)
ans = 0
now = 0
for i in range(1,N+1):
    if S[i] - now >= T:
        ans += T
    else:
        ans += S[i] - now
    now = S[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, T = map(int, input().split())
    end = 0
    ans = 0
    for t in list(map(int, input().split())):
        ans += (t + T) - max(t, end)
        end = t + T
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, T = li_input()
    Ts = li_input()

    L = []

    i = 0
    while i < len(Ts):
        l = [Ts[i]]

        while i + 1 < len(Ts) and Ts[i + 1] - Ts[i] <= T:
            i += 1

        l.append(Ts[i] + T)
        i += 1
        L.append(l)

    ans = 0

    for l in L:
        ans += (l[1] - l[0])

    print(ans)



main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
t = li()

ans = 0

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

ans += x

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

Submission status: Accepted

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

prev = ts[0]
ans = 0
for t in ts[1:]:
    ans += min(T, t - prev)
    prev = t
ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
t_old = -T

for t in t_list:
    diff = t - t_old
    if diff <= T:
        ans += diff
    else:
        ans += T

    t_old = t

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T, *L = map(int, open(0).read().split())
print(sum(min(T, b - a) for a, b in zip(L, L[1:] + [float('inf')])))

Submission status: Accepted

Solution code:
N, T, *L = map(int, open(0).read().split())
print(L[-1] + T - sum(b - a - T for a, b in zip(L, L[1:]) if b - a > T))

Submission status: Accepted

Solution code:
N, T, *L = map(int, open(0).read().split())
a, d = T, 0
for t in L:
    if a < t:
        d += t - a
    a = t + T
print(a - d)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = map(int, input().split())
duration = 0
end = 0
for ti in t:
  duration += ti + T - max(ti, end)
  end = ti + T
print(duration)

Submission status: Accepted

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

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

ans += T

print(ans)

Submission status: Accepted

Solution code:
N,T=map(int, input().split())
TN=list(map(int, input().split()))
a=[0]
b=[]
if N==1:
    print(N)
    exit()
for i in range(1,N):
    if TN[i]>TN[i-1]+T:
        a.append((TN[i-1]+T)-a[-1])
        b.append(a[-1])
        a=[]
        a.append(TN[i])
    if i==N-1:
        a.append(TN[i]+T-a[-1])
        b.append(a[-1])
print(sum(b))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

sumTime = 0

for i in range(N-1):
    dt = tList[i+1] - tList[i]
    if dt < T:
        sumTime += dt
    else:
        sumTime += T

sumTime += T

print(sumTime)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
left = 0
right = 0
for i in a:
    if i-right<=t:
        right = i
    else:
        res += right - left + t
        left = i
        right = i
    #print(left,right,res)
else:
    res += right - left + t

print(res)

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

for i in range(len(t) - 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:
n, t = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a.append(10000000000)
for i in range(1, n + 1):
  ans += min(a[i] - a[i-1], t)
print(ans)

Submission status: Accepted

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

off_total = 0
for i in range(0, n-1):
    if t[i+1] - t[i] > time:
        off_total += t[i+1] - t[i] - time

print(t[-1] + time - off_total)

Submission status: Accepted

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

def main():
    n, t = map(int, input().split())

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

    not_water = []
    for i in range(1, n):
        if t_list[i] - t_list[i-1] > t:
            not_water.append(t_list[i] - t_list[i-1] - t)
    print(max(t_list) + t - sum(not_water))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))
dts = [a - b for a, b in zip(t[1:], t[:-1])]
print(sum(min(dt, T) for dt in dts) + T)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

start = -10
stop = -10
ans = 0
flag = False

for t in tt:
	if stop < t:
		ans += stop-start
		start = t
		stop = t + T
	else:
		stop = t + T

ans += stop-start

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

total_seconds = 0
prev_timing = t_list[0]

for timing in t_list[1:]:
  if timing - prev_timing < t:
    total_seconds += timing - prev_timing
  else:
    total_seconds += t
  prev_timing = timing
total_seconds += t

print(total_seconds)

Submission status: Accepted

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

Submission status: Accepted

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

tt = [0 for i in range(len(t)-1)]
for i in range(len(tt)):
    tt[i] = t[i+1] - t[i]

time = T
for i in tt:
    if i < T:
        time += i
    else:
        time += T

print(time)

Submission status: Accepted

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

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

ans = T
for i in range(1,N):

    if tN[i] - tN[i-1] < T:
        ans += tN[i] - tN[i-1]
    else:
        ans += T

print(ans)

Submission status: Accepted

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

sum_over = 0

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

Submission status: Accepted

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

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

now=t
ans=0

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

print(ans+t)

Submission status: Accepted

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

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

ans = 0
for i in range(n-1):
	if arr[i] + t > arr[i+1]:
		ans += arr[i+1]-arr[i]

	else :
		ans += t

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t = input().split()
N = int(n)
T = int(t)
t_list = []

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

sum_time = 0

for j in range(1,len(t_list)):
	if(t_list[j]-t_list[j-1] <= T):
		sum_time += t_list[j]-t_list[j-1]
	elif(t_list[j]-t_list[j-1] > T):
		sum_time += T

sum_time += T
print(sum_time)

Submission status: Accepted

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

ans = 0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum_time = 0

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

print(sum_time + 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
end = 0
for i in range(N):
    nextEnd = t[i] + T
    ans += nextEnd - max(end, t[i])
    end = nextEnd

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans += rem
print(ans)

Submission status: Accepted

Solution code:
def m():
    n, T = map(int, input().split())
    t = list(map(int, input().split()))
    ans = 0
    for i in range(1, n):
        diff = abs(t[i-1] - t[i])
        if diff <= T:
            ans += diff
            continue
        ans += T
    ans += T
    return ans


print(m())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
end_at = 0
for s in t:
    if end_at >= s:
        ans += s+T-end_at
    else:
        ans += T
    end_at = s+T
print(ans)

Submission status: Accepted

Solution code:
def c_sentou(N, T, time):
    time.append(float('inf'))  # 番兵
    ans = 0
    for i in range(N):
        ans += min(T, time[i + 1] - time[i])
    return ans

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

Submission status: Accepted

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

waste=0
for i in range(N-1):
  if TM[i+1]-TM[i]<T:
    waste+=(T-(TM[i+1]-TM[i]))
print(N*T-waste)

Submission status: Accepted

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

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

print(X[-1]+T)

Submission status: Accepted

Solution code:
n, t = (int(i) for i in input().split())
ts = [int(i) for i in input().split()]
between = []
for i in range(1,n):
    between.append(ts[i]-ts[i-1])
    
ans = t
for d in between:
    if d > t:
        ans = ans + t
    else:
        ans = ans + d
print(ans)

Submission status: Accepted

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

k = 0
s = 0
ans = 0
for p in S:
    if k > p:
        k = p + T
    else:
        ans += k-s
        s = p
        k = p + T

print(ans+k-s)

Submission status: Accepted

Solution code:
def getinputdata():
    # 配列初期化
    array_result = []

    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if (data != ""):

                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result


arr_data = getinputdata()

n = int(arr_data[0][0])
t = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]

mysum = 0
# print(n, t, arr)

for i in range(0, n-1):

    if arr[i + 1] - arr[i] >= t:

        mysum += t
    else:

        mysum += arr[i + 1] - arr[i]

print(mysum+t)

Submission status: Accepted

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

print(total + t)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, intervel = list(map(int, input().split()))
    ts = list(map(int, input().split()))
    ts += [ts[-1] + intervel]

    total_t = 0
    previous_t = ts[0]

    # See:
    # https://atcoder.jp/img/arc073/editorial.pdf
    for i in range(1, n + 1):
        current_t = ts[i]
        total_t += min(current_t - previous_t, intervel)
        previous_t = current_t

    print(total_t)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, intervel = list(map(int, input().split()))
    ts = list(map(int, input().split()))
    ts += [ts[-1] + intervel]

    total_t = 0
    previous_t = ts[0]

    for i in range(1, n + 1):
        current_t = ts[i]

        if (previous_t + intervel) > current_t:
            total_t += max(0, current_t - previous_t)
        else:
            total_t += intervel

        previous_t = current_t

    print(total_t)

Submission status: Accepted

Solution code:
N, T = map(int, input().split(' '))
time = list(map(int, input().split(' ')))
Sumtime = 0
prev = 0
for i in time:
    if i == 0:
        continue
    elif i - prev >= T:
        Sumtime += T
    else:
        Sumtime += i - prev
    prev = i
print(Sumtime + T)

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

Submission status: Accepted

Solution code:
def calc(a, t):
	ans = t
	for i in range(0, len(a)-1):
		if a[i+1]-a[i] < t: ans = ans + a[i+1] - a[i]
		else: ans = ans + t
	return ans

N, T = map(int, raw_input().split())
timelist = map(int, raw_input().split())

print calc(timelist, T)

Submission status: Accepted

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

ans = now = 0
for t in src:
    ans += min(T, t-now)
    now = t
print(ans + T)

Submission status: Accepted

Solution code:
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 0

res = max(b)+a[1]
for i in range(1, len(b)):
    res -= abs(b[i]-b[i-1])-a[1] if abs(b[i]-b[i-1])-a[1] > 0 else 0

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
i=0

while i<n:
    ans+=min(tt[i+1]-tt[i],t)
    i+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    
s = 0
for i in range(n-1):
    p = tl[i + 1] - tl[i]
    if p >= t:
        s = s + t
    else:
        s = s + p
        
s = s + t
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
answer,start = 0,0
if len(a)==1: answer = t
for i in range(1,n):
	if a[i] > a[i-1]+t:
		end = a[i-1]+t
		answer += end-start
		start = a[i]
	if i == n-1:
		end = a[i]+t
		answer += end-start
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = [int(i) for i in 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()))
ts=[]
tf=[]
ts.append(t[0])
tb=t[0]
for i in t:
  if(i>tb+T):
    tf.append(tb+T)
    ts.append(i)
  tb=i
tf.append(t[-1]+T)
time=0
#print(ts)
#print(tf)
for i in range(len(ts)):
  time+=tf[i]-ts[i]
print(time)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1,n):
    if A[i] - A[i-1] <= t:
        cnt += A[i] - A[i-1]
    else:
        cnt += t

print(cnt)

Submission status: Accepted

Solution code:
n,T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = T * len(t)
end = 0
for ti in t:
    if ti <= end:
        ans -= end - ti
    end = ti + 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(n-1):
    if t<a[i+1]-a[i]:
        ans+=t
    else:
        ans+=a[i+1]-a[i]
print(ans+t)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

	else:
		scope.append([t[i],t[i]+T])

total = 0
for begin,end in scope:
	total += (end - begin)

print(total)

Submission status: Accepted

Solution code:
def c_Sentou(N, T, t):
    ans = 0
    for i in range(N):
        if i == N - 1:
            ans += T
            continue
        ans += min(T, t[i + 1] - t[i])
    return ans

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