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 math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    N,T = i_map()
    t = i_list()

    ans = 0
    for i,k in enumerate(t[1:], start=1):
        if k - t[i-1] <= T:
            ans += k - t[i-1]
        else:
            ans += T
    ans += T
    print(ans)



if __name__=="__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

print(res)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

T=list(map(int,input().split()))
ans=0
for i in range(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()))

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

ans = 0
kaku = 0
for n in range(N):
    ans += (t[n]+T)-max(t[n],kaku)
    kaku = max(t[n]+T,kaku)

print(ans)

Submission status: Accepted

Solution code:
# C - Sentou
def main():
    n, t = map(int, input().split())
    s = list(map(int, input().split()))
    cnt = n*t

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


if __name__ ==  "__main__":
    main()

Submission status: Accepted

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

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

ans = P[-1] + T
quit = 0
for p in P:
    if quit < p:
        ans -= p - quit
    quit = p + T

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, t = i_map()
    num_list = i_list()

    ans = n * t

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T, *t = map(int, open(0).read().split())
ans = sum(y-x if y-x < T else T for x,y in zip(t[:N-1],t[1:])) + T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


print(ans)

Submission status: Accepted

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

ans = n*k
for i in range(1, n):
    diff = k - min(t[i] - t[i-1], k)
    ans -= diff
print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
t_lst = list(map(int, input().split()))
accumulate = 0

for i in range(n - 1):
    time = t_lst[i + 1] - t_lst[i]
    accumulate += min(time, t)

accumulate += t
print(accumulate)

Submission status: Accepted

Solution code:
#
# abc060 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 4
0 3"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 4
0 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 1000000000
0 1000 1000000 1000000000"""
        output = """2000000000"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1 1
0"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """9 10
0 3 5 7 100 110 200 300 311"""
        output = """67"""
        self.assertIO(input, output)


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

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

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

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:
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
m=a*b
for i in range(a-1):
  if c[i+1]-c[i]<b:
    m=m-(b-(c[i+1]-c[i]))
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

total = t
time = 0
for i in arr[1:]:
    total += min(t, (i - time))
    time = i

print(total)

Submission status: Accepted

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

T_start = 0
T_end = T
T_total = 0

for i in range(1, N):
    if t[i] <= T_end:
        T_end = t[i] + T
    else: # t[i] > T_end
        T_total += T_end - T_start
        T_start = t[i]
        T_end = t[i] + T

T_total += T_end - T_start

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

Submission status: Accepted

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

sum = 0
for i in range(len(tn)):
  if i < len(tn)-1:
    if tn[i]+t < tn[i+1]:
      sum += t
    else :
      sum += tn[i+1] - tn[i]
  else :
    sum += t

print(sum)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())
t_List = [int(x) for x in input().split()]
pre = 0
ans = T
for t in t_List:
    if t - pre <= T:
        ans += t - pre
    else:
        ans += T
    pre = t
print(ans)

Submission status: Accepted

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

nums = [0]*(n-1)
for i in range(n-1): nums[i] = l[i+1] - l[i]

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

Submission status: Accepted

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

Submission status: Accepted

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

dt = []
for i in range(N - 1):
  dt.append(t[i + 1] - t[i])
else:
  dt.append(T)

print(sum([min([dti, T]) for dti in dt]))

Submission status: Accepted

Solution code:
'''
Created on 2020/08/16

@author: harurun
'''
N,T=map(int,input().split())
t=list(map(int,input().split()))
ans=T
s=t[0]
for i in range(1,N):
  if t[i]-s>=T:
    ans+=T 
  else:
    ans-=T-(t[i]-s)
    ans+=T
  s=t[i]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

s = n * t
for i in range(1,n):
    if T[i] - T[i-1] < t:
        s -= (t-(T[i]-T[i-1]))
print(s)

Submission status: Accepted

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()

def main():
    N, T = map(int, input().split())
    A = deque(map(int, input().split()))
    time = 0
    start = 0
    stop = 0
    while A:
        a = A.popleft()
        if stop < a:
            time += stop - start
            start = a
            stop = a + T
        else:
            stop = a + T
    print(time + stop - start)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
s=0
z=0
for i in l:
    if z-i>0:
        s+=i+t-z
    else:
        s+=t
    z=i+t
print(s)

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans, now = 0, 0
for i in t:
    if i < now:
        ans -= now - i
    ans += T
    now = i + T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = (int(T) for T in input().split())
Per = [int(T) for T in input().split()]
Wat = 0
for X in range(0,N-1):
    if Per[X]+K<=Per[X+1]:
        Wat += K
    else:
        Wat += Per[X+1]-Per[X]
print(Wat+K)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,T=map(int,input().split())
t=list(map(int,input().split()))
t.append(10**10)
ans=0
flg=0
temp=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans += T
print (ans)

Submission status: Accepted

Solution code:
N, T = [int(x) for x in input().split()]
t_list = [int(x) for x in input().split()]
t_s = t_e = ans = 0
for t in t_list:
    if t > t_e:
        ans += t_e - t_s
        t_s = t
    t_e = t + T
ans += t_e - t_s
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans+T)

Submission status: Accepted

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

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

print(ans+T)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
l=list(map(int,input().split()))
s=0
pre_end=0
for tt in l:
  time=t-max(0, pre_end - tt)
  s+=time
  pre_end=tt+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(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:
import math

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *t = map(int, read().split())

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

    print(ans)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans+T)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    N,T=map(int,stdin.readline().strip().split())
    t=list(map(int,stdin.readline().strip().split()))

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

if __name__=='__main__':
    main()

Submission status: Accepted

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

res = 0
time = 0
for v in t:
    if v < time:
        res += T - time + v
        time += T - time + v
    else:
        res += T
        time = T + v

print(res)

Submission status: Accepted

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

for i in range(N-1):
  tmp = t[i+1] - t[i]
  if tmp > T:
    d.append(T)
  else:
    d.append(tmp)

print(sum(d)+T)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for n in range(N-1):
  a+=min(S,T[n+1]-T[n])

print(a)

Submission status: Accepted

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

ans=0

for t_idx in range(len(A)-1):
    if A[t_idx] + T <= A[t_idx+1]:
        ans += T
    else:
        ans += A[t_idx+1]-A[t_idx]
ans+=T

print(ans)

Submission status: Accepted

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

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

ans = T

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in l:
    now = i
    #print(now,latest,t)
    if now-latest >= t:
        ans += t
    else:
        ans += now-latest
    
    latest = now
ans += t
print(ans)

Submission status: Accepted

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

ans = 0
now = 0
for i in ts[1:]:
    if i<=now+t:
        ans += i-now
    else:
        ans += t
    now = i
print(ans+t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, T = mi()
    t = list(mi())
    l = [max(t[i+1]-t[i]-T, 0) for i in range(N-1)]
    print(t[-1]+T-sum(l))


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

Submission status: Accepted

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

ans=t[-1]+T

for i in range(1,N):
    p=t[i]-t[i-1]
    if p>T:
        ans-=p-T

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
lst = list(map(int, input().split())) + [10 ** 12]
sec = 0
for i in range(n):
  sec += min(t, lst[i + 1] - lst[i])
print(sec)

Submission status: Accepted

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

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

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:
#!/usr/bin/env python3 

n, T = map(int, input().split())
t = list(map(int, input().split()))
dt = [0 for _ in range(n-1)]

for i in range(n-1):
    dt[i] = t[i+1]-t[i]

ans = 0 
for i in range(n-1):
    if dt[i] <= T:
        ans += dt[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
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, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, T = il()
    time = il()

    ret = T
    for n in range(N-1):
        ret += min(abs(time[n] - time[n + 1]), T)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
tmp = 0

for i in t:
    if tmp < i:
        ans += T
    else:
        ans += T - (tmp - i)
    tmp = i + T
print(ans)

Submission status: Accepted

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

S = N*T

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

print(S)

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:
n,t = map(int,input().split())
st = list(map(int,input().split()))

st += [10**10]
t1 = 0
t2 = 0
ans = 0
for ti in st:
  if t2 < ti:
    ans += t2-t1
    t1 = ti
  t2 = ti+t
print(ans)