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
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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

ans = T
for x, y in zip(time[:-1], time[1:]):
    ans += min(T, y - x)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n, t, *lst = map(int, sys.stdin.read().split())
cur, res = 0, 0
for i in lst:
  if i <= cur + t:
    res += i - cur
  else:
    res += t
  cur = i
res += t
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(N):
    if i!=N-1:
        if t[i+1]-t[i]>=T:
            ans+=T
        else:
            ans+=t[i+1]-t[i]
    else:
        ans+=T
print(ans)

Submission status: Accepted

Solution code:
n,T=[int(_) for _ in input().split()]
t=[int(_) for _ in 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())
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


def read():
    N, T = map(int, input().strip().split())
    U = map(int, input().strip().split())
    return N, T, U


def solve(N, T, U):
    tsum = 0
    t0 = 0
    for t1 in sorted(list(U)):
        if t1 - t0 < T:
            tsum += t1 - t0
        else:
            tsum += T
        t0 = t1
    return tsum + T


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    N, T = map(int, input().split())
    *t, = map(int, input().split())
    t += [1 << 31]

    u = iter(t)
    next(u)

    ans = sum(min(T, u_ - t_) for t_, u_ in zip(t, u))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
times = list(map(int, input().split()))
ans = 0
t = 0
for time in times:
    if time >= t:
        ans += T
        t = time + T
    else:
        diff = t - time
        ans += T - diff
        t = time + T
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,T = map(int,input().split())


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

res = T


for i in np.diff(np.array(t)):
    res += min(T,i)

print(res)

Submission status: Accepted

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

print(ans + T)

Submission status: Accepted

Solution code:
import numpy as np

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

diff = np.diff(t)

ans = T
for i in diff:
    ans += min(i, T)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, t = map(int, input().split())
tt = readints()
cnt = t

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N, T = readnums()
    t = list(readnums())

    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

last = -1
ans = 0
for t in T:
    if t <= last:
        ans += Y - (last - t)
    else:
        ans += Y
    last = t + Y

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = 0

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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 = T
for i in range(N-1):
    ans += min(t[i+1]-t[i],T)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n,t = map(int,input().split())
    tl = list(map(int,input().split()))
    res = t
    for i in range(1,n):
        res += t - max((tl[i-1]+t-tl[i]),0)
    print(res)

if __name__ == '__main__':
    main()

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

    print(res + t)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[24]:


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


# In[25]:


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


# In[ ]:

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#ABC073-C
n,t = map(int,input().split())
time = list(map(int,input().split()))

cnt = t

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

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()))
LST = []

for a in A:
  LST.append((a,1))
  LST.append((a+T,-1))
  
LST.sort()

prev = -1
s = 0
ans = 0
for x,y in LST:
  if y == 1:
    s += 1
    if s == 1:
      prev = x
  elif y == -1:
    s -= 1
    if s == 0:
      ans += (x - prev)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sum_second = 0
for i in range(N):
    if (i == N - 1):
        sum_second += T
        break

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

    # if T > t[i + 1] - sum_second:
    #     sum_second += t[i + 1] - sum_second
    # elif (T <= t[i + 1] - sum_second):
    #     sum_second += T


print(sum_second)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

Solution code:
#ARC73-C
n,T=map(int,input().split())
t=list(map(int,input().split()))
e=T
total=T
for i in range(1,n):
    if t[i]<e:
        total=total-(e-t[i])+T
        e=t[i]+T
    else:
        e=t[i]+T
        total+=T
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    IN1 = [int(_) for _ in input().split()]
    N = IN1[0]
    T = IN1[1]
    times = [int(_) for _ in input().split()]

    result = 0
    before = 0
    base = 0 
    for i in range(1, len(times)):
        time = times[i]
        if time - before > T:
            result = result + before + T - base
            base = time
        before = time
    result = result + times[len(times)-1] + T - base
    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, T = map(int, readline().split())
    t = list(map(int, readline().split()))
    ans = T
    for i in range(N-1):
        ans += min(T, t[i+1]- t[i])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

interval=[]
for i in range(N-1):
    if Time[i+1]-Time[i]>T:
        interval.append(Time[i+1]-Time[i])

k=len(interval)
print(Time[-1]+T-(sum(interval)-k*T))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans_t)

Submission status: Accepted

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

ans = 0
s = 0
e = T
for n in t[1:]:
    if e < n:
        ans += e - s
        s = n
    e = n + T
ans += e - s
print(ans)

Submission status: Accepted

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

p = 0
ans = 0
for time in times:
    start = min(p, time)
    ans += t - max(0, p - time)
    p = time + t
print(ans)

Submission status: Accepted

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

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 = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
start = 0
stop = 0
ans = 0
for i in range(len(t)):
    start = max(stop, t[i])
    stop = t[i] + T
    ans += stop - start
print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, T = LI()
t = LI()
ans = 0
time = 0
for i in t:
    if time < i:
        time = i + T
        ans += T
    else:
        ans += i - time + T
        time = i + T
print(ans)

Submission status: Accepted

Solution code:
def main():
    from itertools import tee, zip_longest

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

    iter_t = iter(t)
    next(iter_t)

    ans = sum(min(T, t1 - t0) for t0, t1 in zip_longest(t, iter_t, fillvalue=1 << 31))

    print(ans)


if __name__ == '__main__':
    main()

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

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,T=pin()
    t=tupin()

    ans=0
    for i in range(1,N):
        temp=t[i]-t[i-1]
        if temp>T:ans+=T
        else: ans+=temp
    print(ans+T)
#%%submit!
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,T = map(int,input().split())
t = list(map(int,input().split()))
h = 0
for i in range(1,n):
    if t[i] - t[i-1] < T:
        h += T - (t[i] - t[i-1])
print(T*n - h)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for num, s in enumerate(ts):
    try:
        if ts[num] + t <= ts[num+1]:
            ans += t
        else:
            ans += ts[num+1] - ts[num]
    except:
        pass
ans += t
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N,T = map(int,input().split())
    t = list(map(int, input().split()))
    dup = 0
    for i in range(N-1): #enumerateはendが選択できない
        if t[i+1] < t[i] + T:
            dup += T-(t[i+1] - t[i])

    print(N*T - dup)




if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

N, T = mii()
t = lmii()

p = []
t.sort()

st = t[0]
ed = t[0] + T
for i in range(1, N):
    n_st = t[i]
    n_ed = n_st + T

    if st <= n_st <= ed:
        ed = n_ed
    else:
        p.append((st, ed))
        st, ed = n_st, n_ed

p.append((st, ed))

ans = 0
for st, ed in p:
    ans += ed - st

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/arc073/tasks/arc073_a
# 愚直でよくね？
N, T = read_ints()
t = read_ints()

ans = 0
# t(i+1)<ti+Tだったら差を足してそうじゃなければTを足すのが良さそう
for i in range(N - 1):
    if t[i + 1] < t[i] + T:
        ans += t[i + 1] - t[i]
    else:
        ans += T
ans += T  # 最後の人
print(ans)

Submission status: Accepted

Solution code:
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 heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
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 = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
A = LIST()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n, time = 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], time)
    print(ans+time)
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):
  ans+=min(T,t[i]-t[i-1])
ans+=T
print(ans)

Submission status: Accepted

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

  for t in tt:
    if t >= last:
      ans += T
      last = t + T
    else:
      ans += t + T - last
      last = t + T

  print(ans)

  return

if __name__ == "__main__":
  resolve()

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
t.append(t[-1] + 2 * T)

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

print (ans)

Submission status: Accepted

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

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

    print(ans)

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

Submission status: Accepted

Solution code:
import numpy as np
N, T = map(int, input().split())
t = np.array(input().split(), dtype=int)

dt = np.diff(t)
dt = np.minimum(dt, T)
print(T + dt.sum())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

def it():
    for i in range(N-1):
        diff = ts[i+1] - ts[i]
        if diff <= T:
            yield diff
        else:
            yield T
    yield T

print(sum(it()))