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, 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, K = il()
    T = il()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, T = MI()
    t = LI()
    x = 0
    for i in range(n-1):
        diff = t[i+1] - t[i]
        x += min(diff, T)
    x += T
    print(x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, t = map(int, readline().split())
    a = list(map(int, readline().split()))
    ans = 0
    end = 0
    for x in a:
        if end <= x:
            ans += t
            end = x + t
        else:
            ans += (t - (end - x))
            end = x + t
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, add_time = map(int, input().split())
    times = list(map(int, input().split()))

    ans = add_time
    prev_finish = add_time
    for time in times:
        if time <= prev_finish:
            ans += add_time - (prev_finish - time)
        else:
            ans += add_time
        prev_finish = time + add_time
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
a=list(map(int,input().split()))
a.append(10**10)
ans=0
b=-1
e=-1
for i in a:
  if e<i:
    ans+=(e-b)
    b=i
  e=i+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(n-1):
  ans+=min(t,a[i+1]-a[i])
print(ans)

Submission status: Accepted

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



print(ans)

Submission status: Accepted

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


def solve(N: int, T: int, t: "List[int]"):
    a = [[t[0]]]
    for tt in t[1:]:
        if a[-1][-1] + T < tt:
            a.append([tt])
        else:
            a[-1].append(tt)
    b = [aa[-1] - aa[0] + T for aa in a]    
    return sum(b)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    t = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, T, t))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(U))

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

ans=0
time=[]
time.append([t[0],t[0]+T])
for i in range(1,N):
    if time[-1][0]<t[i] and t[i]<=time[-1][1]:
        time[-1]=[time[-1][0],t[i]+T]
    else:
        ans+=time[-1][1]-time[-1][0]
        time.append([t[i],t[i]+T])

ans+=time[-1][1]-time[-1][0]
print(ans)

Submission status: Accepted

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

for i in tl:
    ans += min(t, i - pre)
    pre = i
    
print(ans)

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

Submission status: Accepted

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

for i in tl:
    if i - pre >= t:
        ans += t
        pre = i
    else:
        ans += i - pre
        pre = i
    
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,max_t=map(int,readline().split())
    t=list(map(int,readline().split()))

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

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

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

counter=0
last_pushed=0
for t in list_t:
  if t<=last_pushed+T:
    # print("t",t)
    # print("last_pushed+T",last_pushed+T)
    #水がまだ出ている状態なら
    counter+=(t-last_pushed)
    last_pushed=t
    #最後に押した時間を変えて終了
  elif t>last_pushed+T:
    #水が止まっている状態なら
    counter+=T
    last_pushed=t

print(counter+T)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(X)

Submission status: Accepted

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

count = 0

for i, yt in enumerate(t):
    try:
        x = t[i + 1]
    except IndexError:
        count += T
        break

    if (t[i + 1] - yt) <= T:
        count += t[i + 1] - yt
    else:
        count += T

print(count)

Submission status: Accepted

Solution code:
# arc073_a.py
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:
n,t=map(int,input().split())
a=list(map(int,input().split()))

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

Submission status: Accepted

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

ans = 0
prev_t = tl[0]
for t in tl[1:]:
  ans += min(t - prev_t, T)
  prev_t = 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 numpy as np

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

t = np.append(t[1:], t[-1]+T) - t #隣との差分の行列
t = list(sorted(t))

borderIndex = t.index(T)

ans = int(sum(t[0:borderIndex]) + np.int64(len(t[borderIndex:])*T))
print(ans)

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
total, prev = 0, 0
for tl in map(int, input().split()):
    total += min(tl - prev, t)
    prev = tl
print(total + t)

Submission status: Accepted

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

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

Submission status: Accepted

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

if N == 1:
  print(T)
else:
  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())
s = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
total, prev = 0, 0
for t in map(int, input().split()):
    total += min(t - prev, T)
    prev = t
print(total + T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N, T = map(int,input().split())
    t = list(map(int,input().split()))
    t.append(float('inf'))

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, T = map(int, input().split())
    t = list(map(int, input().split()))
    
    ans = T
    pre = t[0]
    for tt in t:
        if tt - pre < T:
            ans += tt - pre
        else:
            ans += T
        pre = tt
    print(ans)
               
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans + t)

Submission status: Accepted

Solution code:

def main():
    N,T  = map(int, input().split()) 
    A = list(map(int, input().split())) 
    cnt  = 0
    temp = 0

    for i in range(N):
        if temp > A[i]:
            cnt += T-temp+A[i]
        else:
            cnt += T
        temp = A[i] + T
    print(cnt)




if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

# t_list = [a, b, c,]
# 	              stop_time = 0, total_time = 0
#    a      a+T 
#    <----->          [??, stop_time) [a, a+T) (no overlap) a+T, total_time+T
#        b      b+T
#        <----->      [??, stop_time) [b, b+T) (overlap) b+T, total_time+(b+T-stop_time)
#                  c      c+T
#                  <----->
#                     [??, stop_time) [c, c+T) (no overlap) c+T, total_time+T

stop_time, total_time = 0, 0
for x in t_list:
  # [x, x+T)
  if stop_time <= x:
    # no overlap
    total_time += T
  else:
    # overlap
    total_time += ((x + T) - stop_time)
  stop_time = x + T

print(total_time)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
tlist = [0] + list(map(int,input().split()))
tsum = 0
restart = tlist[1]

for i in range(1,n+1):
  if tlist[i] <= t + tlist[i-1]:
    sumtmp = t+tlist[i] - restart
  elif tlist[i]  > t + tlist[i-1]:
    tsum += sumtmp
    restart = tlist[i]
    sumtmp = t
    
print(tsum + sumtmp)

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############



N,T = IL()
A = IL()

ans = T

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

Submission status: Accepted

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

ans = T

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,T=map(int,input().split())
    t=list(map(int,input().split()))
    ans=0
    tmp=0
    for x in t:
        if x>=tmp:
            ans+=T
        else:
            ans+=T-(tmp-x)
        tmp=x+T
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = n*t

for i in range(1,n):
    if tl[i]-tl[i-1] <t:
        res -= t- (tl[i]-tl[i-1])

print(res)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[n, conti_time] = map(int, input().split())
t = list(map(int, input().split()))

cnt = 0
tmp_start_time = 0
tmp_end_time = 0

for i in t:
  if tmp_end_time <= i:
    cnt += tmp_end_time - tmp_start_time
    tmp_start_time = i
    tmp_end_time = i + conti_time
  else:
    tmp_end_time = i + conti_time

cnt += tmp_end_time - tmp_start_time

print(cnt)

Submission status: Accepted

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

pre = 0
total = 0
for i in range(N):
    if t[i] - pre <= T:
        total += t[i] - pre
    else:
        total += T
    pre = t[i]
    
print(total+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())
X=list(map(int,input().split()))
ans=0
r=0
for x in X:
  if r<=x:
    ans+=T
    r=x+T
  else:
    ans+=x+T-r
    r=x+T
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(len(t)):
    if i == len(t) - 1:
        X += T
    else:
        if t[i+1] - t[i] < T:
            X += t[i+1] - t[i]
        else:
            X += T
print(X)

Submission status: Accepted

Solution code:
n,t = map(int,input().split())
t_list = list(map(int,input().split()))
ans = 0
stop = -1
for time in t_list:
  if time >= stop:
    ans += t
    stop = time + t
  else:
    ans += t + time - stop
    stop = time + t
print(ans)

Submission status: Accepted

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,t=MI()
lis=LI()
ans=0
for i in range(n-1):
    ans+=min(t,lis[i+1]-lis[i])
print(ans+t)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 16:15:19 2020

@author: shinba
"""

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

T = list(map(int,input().split()))
T.append(10**10)
R = []
for i in range(n):
    R.append(T[i+1]-T[i])

ans = 0
start = T[0]

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

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)
######################################################################################################
def main():
    N,tt=map(int,input().split())
    T=list(map(int,input().split()))
    T.sort()
    ans=0
    owaru=-inf
    for t in T:
        if t>=owaru:
            ans+=tt
        else:
            ans+=tt-(owaru-t)
        owaru=t+tt
    print(ans)
main()

Submission status: Accepted

Solution code:
def main():
    n, t, *s = map(int, open(0).read().split())
    ans = 0
    s = [0] + s
    for i, j in zip(s, s[1:]):
        if j - i >= t:
            ans += t
        else:
            ans += j - i
    else:
        ans += t

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(sum([min(t2 - t1, T) for t1, t2 in zip(times[:-1], times[1:])]) + T)