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:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    ans += min(T, t[i + 1] - t[i])
ans += T
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, T = [int(item) for item in input().split()]
    t_list = [int(item) for item in input().split()]
    time = 0

    for i in range(N):
        if i == 0:
            time = T
        else:
            delta_time = t_list[i] - t_list[i-1]
            time += min(T, delta_time)
            
    print(time)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, t = map(int, input().split())
    T = list(map(int, input().split()))

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

    print(res + t)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,T = map(int,input().split())
arrT = list(map(int,input().split()))

start = arrT[0]
end = 0
ans = 0
for i in range(N):
    if i == N-1:
        if arrT[i-1]+T>=arrT[i]:
            end = arrT[i]
            num = end-start+T
            ans += num
        else:
            ans += T
    elif arrT[i]+T>=arrT[i+1]:
        end = arrT[i]
        continue
    else:
        end = arrT[i]
        num = end-start+T
        ans += num
        start = arrT[i+1]

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

res += T

print(res)

Submission status: Accepted

Solution code:
def myAnswer(N:int,T:int,t:list) -> int:
   total = T*N
   sub = 0
   if(N == 1): return T
   pre = t.pop(0)
   for time in t:
      if(pre + T - time > 0):
         sub += pre+T - time
      pre = time
   return total - sub

def modelAnswer():
   return
def main():
   N,T = map(int,input().split())
   t = list(map(int,input().split()))
   print(myAnswer(N,T,t[:]))
if __name__ == '__main__':
   main()

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,t = iim()
T = iil()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

before = t[0]
ans = 0
for ti in t[1:]:
    if ti - before <= T:
        ans += ti - before
    else:
        ans += T
    before = ti
print(ans + T)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split(' '));T=list(map(int,input().split(' ')))
total = 0
tstart, tend = T[0],T[0]+t
i = 1
while i < n:
    if T[i] > tend:
        total += (tend-tstart)
        tstart,tend = T[i],T[i]+t
    else:
        tend = T[i]+t
    i += 1
total += (tend-tstart)
print(total)

Submission status: Accepted

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

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

diff = []

for i in range(N - 1):
    diff.append(t[i+1] - t[i])

# print(diff)

shower_time = list(map(lambda x: T if T < x else x, diff))
ans = sum(shower_time) + T

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(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
for i in range(n-1):
  if a[i+1]-a[i]>=t:
    ans+=t
  else:
    ans+=(a[i+1]-a[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 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:
import sys
n,t = map(int,input().split())
li = list(map(int,input().split()))
count = t
if n == 1:
    print(t)
    sys.exit()
for i,l in enumerate(li):
    if i == 0:
        continue
    if l - li[i-1] <= t:
        count += l - li[i-1]
    else:
        count += t
print(count)

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:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
n, t = map(int, input().split()) # 入力が複数
people = [int(i) for i in input().split()] # 配列で数字

ans = 0
pre = 0
for i in range(n):
    if pre >= people[i]:
        ans += t - (pre - people[i])
    else:
        ans += t
    pre = people[i] + 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(0, N - 1):
    ans += min(Ts[i + 1] - Ts[i], T)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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 = time[i] + t
    else:
        c = (wait - time[i])
        ans -= c
        ans += t
        wait = time[i] + t

print(ans)

Submission status: Accepted

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

open = [t[0] + T]
ans = T
for n in range(N):
    if n == 0:
        continue
    else:
        if t[n] >= open[-1]:
            ans += T
            open.append(t[n] + T)
        else:
            ans += t[n] - t[n-1]
            open.append(t[n] + T)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, dT = map(int, input().split())
T = list(map(int, input().split())) + [float('inf')]
ans = 0
for i in range(N):
    ans += min(dT, 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 = 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()))
t.append(t[-1]+T+1)
ans=0
for i in range(n):
  ans += min(T,t[i+1]-t[i])
print(ans)

Submission status: Accepted

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


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

ans = 0

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

print(ans + T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc073c

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

Submission status: Accepted

Solution code:
import numpy as np
N, T = list(map(int, input().split()))
t = np.array(list(map(int, input().split())))
tT = np.sort(t)[::-1] + T

total = tT[0]
for i in range(1, N):
  total -= max(tT[i-1] - tT[i]-T, 0)
  
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = T
time = T

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

o = T
for i, j in zip(t, t[1:]):
  o += min(j-i, T)
print(o)

Submission status: Accepted

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

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

print(dur)

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

print(ans + T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T, *t_l = map(int, open(0).read().split())
ans = 0
t_before = 0
for t in t_l:
    ans += min(t-t_before, T)
    t_before = t
print(ans+T)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
import numpy as np


def main():
	n,t=map(int,input().split())
	T=list(map(int,input().split()))
	T=np.array(T)
	diff=T[1:]-T[:-1]
	time1=diff[diff<=t]
	time2=len(diff[diff>t])*t
	print(time1.sum()+time2+t)



if __name__ == "__main__":
	main()

Submission status: Accepted

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

    dp = [0] * N
    dp[0] = t[0]
    for i, tt in enumerate(t):
        if i == N-1:
            ans += T
            break
        if tt + T > t[i+1]:
            ans += t[i+1] - tt
        else:
            ans += T
    print(ans)

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for t1, t2 in zip(T, T[1::]):
  if t2 - t1 < t:
    ans += t2 - t1
  else:
    ans += t
  
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, T = map(int,input().split())
t = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    A = [int(t) for t in input().split()]

    Ans = 0
    currentTime = A[0]
    for i in range(1, N):
        if A[i] - currentTime < T: Ans += A[i] - currentTime
        else: Ans += T
        currentTime = A[i]
    Ans += T
    print(Ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(1, len(t)):
	if t[i] - t[i-1] < j:
		ans += (t[i] - t[i-1])
	else:
		ans += j

print(ans + j)

Submission status: Accepted

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

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

total += T

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=list(map(int, input().split()))
c=list(map(int, input().split()))

x=0
y=0
z=0
ans=0
for i in range(a-1):
	x=c[i]
	if c[i]<=c[i+1]-b:
		ans=ans+b
	else:
		ans=ans+c[i+1]-c[i]
print(ans+b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for i in range(0, 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())
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: Accepted

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

ans = t + 0
cum_time = 0
for d in data:
    dt = d - cum_time
    if dt < t:
        lost = t - dt
        ans -= lost
    ans += t
    cum_time += dt

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,T = input().split()
T = int(T)
L = [int(x) for x in input().split()]
R = 0
for i in range(len(L) - 1):
    su = L[i+1] - L[i]
    R += min([su,T])
print(R+T)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = 0

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

sum = sum + T

print(sum)

Submission status: Accepted

Solution code:
n, t = (int(x) for x in input().split())
t_l = [int(x) for x in input().split()]
ans = s = 0
for t_i in t_l:
    if s <= t_i:
        ans += t
    else:
        ans += (t_i - s) + t
    s = t_i + t
print(ans)

Submission status: Accepted

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

Times = list(input().split())
time = 0

for i in range(N - 1):
    if int(Times[i]) + T <= int(Times[i + 1]):
        time += T
    else:
        time = time + (int(Times[i + 1]) - int(Times[i]))

print(time + T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
    
    return 0

#input


N,T=pin()
timing=tuple(pin())

ans=0
for i in range(N):
        if i!=(N-1):ans+=min(timing[i+1]-timing[i],T)
        else:ans+=T
print(ans)
#output
#print(solution(H,N))
#print(["No","Yes"][cond])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
    
    return 0

#input


N,T=pin()
timing=list(pin())

ans=0
for i in range(N):
        if i!=(N-1):ans+=min(timing[i+1]-timing[i],T)
        else:ans+=T
print(ans)
#output
#print(solution(H,N))
#print(["No","Yes"][cond])