Problem:


Score : 300 points

Problem Statement

In a public bath, there is a shower which emits water for T seconds when the switch is pushed.

If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.

N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.

How long will the shower emit water in total?

Constraints

1 ≤ N ≤ 200,000

1 ≤ T ≤ 10^9

0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9

T and each t_i are integers.

Input

Input is given from Standard Input in the following format:

N T
t_1 t_2 ... t_N

Output

Assume that the shower will emit water for a total of X seconds. Print X.

Sample Input 1

2 4
0 3

Sample Output 1

7

Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

Sample Input 2

2 4
0 5

Sample Output 2

8

One second after the shower stops emission of water triggered by the first person, the switch is pushed again.

Sample Input 3

4 1000000000
0 1000 1000000 1000000000

Sample Output 3

2000000000

Sample Input 4

1 1
0

Sample Output 4

1

Sample Input 5

9 10
0 3 5 7 100 110 200 300 311

Sample Output 5

67



Sample input:
2 4
0 3


Sample output:
7

Submission status: Accepted

Solution code:
n,t = map(int, input().split())
a = list(map(int, input().split()))
ans=0
last_start=0
for i in range(1,len(a)):
    if last_start + t > a[i]: # continuous
        ans += (a[i] - last_start)
    else: # stop -> start
        ans+=t
    last_start=a[i]
ans+=t

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(time + t)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N,T = Scanner.map_int()
    A = Scanner.map_int()

    ans = 0
    prev = 0
    for i in range(N):
        ans += T
        ans -= max(0,prev - A[i])
        prev = A[i] + T
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

total = T
now = T

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

diff_t = [t_list[i+1] - t_list[i] for i in range(N-1)]

ans = 0
for dt in diff_t:
    if dt <= T:
        ans += dt
    else:
        ans += T

ans += T
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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())
tlst=list(map(int,input().split()))
value=0
mae=0
for i in range(1,N):
    value+=min(tlst[i]-tlst[i-1],T)

value+=T
print(value)

Submission status: Accepted

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

Submission status: Accepted

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

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
t_diff=[t[i+1]-t[i] for i in range(N-1)]
for i in t_diff:
    if i>T:
        ans+=T
    else:
        ans+=i
# 差分で足し合わせたので最後は計算に入ってない、最後は必ず被らないのでTを加える
print(ans+T)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
time = list(map(int, input().split()))
sub_list = []
for i in range(1,n):
    sub_list.append(time[i] - time[i-1])

not_water = 0
for i in sub_list:
    if i > t:
        not_water += (i - t) 
print(time[-1] + t - not_water)

Submission status: Accepted

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

d = 0
for i in range(n-1):
    d += max(0, t - T[i+1] + T[i])
    
print(n*t - d)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

else:
    ans += T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
ans = 0
for i in range(n):
    if i == 0:
        before = t_li[i]
        ans = t_li[i] + t
        continue
    
    if ans < t_li[i]:
        cnt += t_li[i] - ans
        ans = t_li[i] + t
    else:
        ans = t_li[i] + t
        
print(ans - cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int,input().split())
List = list(map(int,input().split()))
Data = [0,0]
for item in List:
  if Data[0]>=item:
    Data[1] += T + item -Data[0]
    Data[0] = item +T
  else:
    Data[1] += T
    Data[0] = item +T
print(Data[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
li = list(map(int, input().split()))
li = li[::-1]
ans = 0

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

Submission status: Accepted

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

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

ans += T
print(ans)

Submission status: Accepted

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

a.append(1000000000000)

an = 0

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

Submission status: Accepted

Solution code:
import sys


def slove():
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    tl = list(map(int, input().rstrip('\n').split()))
    mt = 0
    for i in range(n-1):
        mt += (min(tl[i] + t, tl[i+1]) - tl[i])
    print(mt + t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
until = 0
for t in ts:
    ans += min(T, t+T-until)
    until = t+T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(x)

Submission status: Accepted

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

now = 0
end = 0
ans = 0
for i in range(N):
    a = A[i]
    ans += min((T-(end-a)),T)
    now = a
    end = a+T
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = tuple(map(int, input().split()))
t = list(map(int, input().split()))
if N == 1:
    print(T)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os

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

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

Submission status: Accepted

Solution code:
n, T = [int(el) for el in input().split(' ')]
s = [int(el) for el in input().split(' ')]
total = 0
for i in range(n-1):
    total += min(T, s[i+1]-s[i])
print(total + T)

Submission status: Accepted

Solution code:
N, T = map(int,input().split())
t = list(map(int,input().split()))
s = 0
start = 0
end = 0
for p in t:
  if end > p:
    end = p+T
  else:
    s += (end - start)
    start = p
    end = p+T
s += end - start
print(s)

Submission status: Accepted

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

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

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:
a,b = map(int,input().split())
ls = list(map(int, input().split()))

duration = 0 
max = 0

for i in ls :
  if  i <= max and max <= i+b :	
    duration += i + b - max  
    max = i + b
    
  elif max < i :
    duration += b
    max = i + b
    
print(duration)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
people = list(map(int, input().split()))
people.append(people[-1]+ t+1)
if n == 1:
    print(t)
else:
    time = 0
    for i in range(n+1):
        if i ==0:
            togire = False
            start = people[i]
            continue
        if people[i] - people[i-1] > t:
            togire = True
            time += people[i-1] - start + t
            start = people[i]
        else:
            togire = False
    print(time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    T = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(1, n):
        cnt += min(T[i] - T[i-1], t)
    print(cnt + t)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

res = 0
pre = -1e10
for t in [int(v) for v in input().split()]:
    res += T

    if pre + T > t:
        res -= (pre + T) - t
    pre = t

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC073C
import copy
import sys
import math

#n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

n=hoge[0]
t=hoge[1]

total=n*t
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,n-1):
	if(hoge[i+1]-hoge[i]<t):
		total-=t-(hoge[i+1]-hoge[i])
print(total)

Submission status: Accepted

Solution code:
import copy
N, T = map(int, input().split())
t = list(map(int, input().split()))
tmp = copy.deepcopy(t)
for i in range(1, N):
    t[i] = tmp[i] - tmp[i-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

ans += left
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, T = map(int, input().split())
a = list(map(int, input().split()))
total_t, a_len = 0, len(a)

for i in range(a_len - 1):
    if a[i] + T > a[i + 1]: 
        total_t += a[i + 1] - a[i]
    else: 
        total_t += T

print(total_t + T)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, T = map(int, input().split())
a = list(map(int, input().split()))
total_t, crrnt_t, a_len = 0, 0, len(a)

for i in range(a_len - 1):
    if a[i] + T > a[i + 1]: 
        total_t += a[i + 1] - a[i]
    else: 
        total_t += T
    crrnt_t = a[i + 1]

print(total_t + T)

Submission status: Accepted

Solution code:
N, T = map(int,input().split())
t = list(map(int,input().split()))
ruiseki = 0
start = 0
for i in range(N-1):
    if t[i+1]-start <= T: #ある人が押してから次の人が押すまでの時間がT以下のとき、その区間では流れ続けてる
        ruiseki += t[i+1]-start
    else:
        ruiseki += T
    start = t[i+1]
print(str(ruiseki+T))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
L = list(map(int, input().split()))
L.insert(0, 0)
L.append(float('inf'))
ans = 0
for t in range(1, N+2):
    ans += min(L[t] - L[t-1], T)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


def solve(N: int, T: int, t: "List[int]"):
    l = [t[i+1]-t[i] if (t[i+1]-t[i] < T) else T for i in range(N-1) ]
    print(sum(l)+T)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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]"
    solve(N, T, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

l = [t[0]]
for i in range(1, N):
    l.append(t[i] - t[i - 1])

ans = 0

for ll in l:
    if ll < T:
        ans += ll
    else:
        ans += T

print(ans + T)

Submission status: Accepted

Solution code:
# ARC073C - Sentou (ABC060C)
def main():
    n, t = list(map(int, input().rstrip().split()))
    lst = list(map(int, input().rstrip().split()))
    ans, cur = 0, lst[0]
    for i in lst[1:]:
        ans += min(t, i - cur)
        cur = i
    ans += t
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,T=(int(i) for i in input().split())
t=[int(i) for i in input().split()]
#print(n,T,t)
ans=0
if n==1:
  ans=T
else:
  for i in range(1,n):
    ans+=min(t[i]-t[i-1],T)
  ans+=T
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
n, t = map(int, input().split())
a = list(map(int, input().split()))
sp = 0
ep = t
total = 0

# calc
for i in range(1, n):
    if a[i] <= ep:
        ep = a[i]+t
    elif a[i] > ep:
        total += ep-sp
        sp = a[i]
        ep = a[i]+t
# output
total += ep-sp
print(total)

Submission status: Accepted

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

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

print(t_water + T)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
*push, = map(int, input().split())
ans = 0
current = -T
for t in push:
    offset = max(current + T - t, 0)
    ans += T - offset
    current = t
print(ans)

Submission status: Accepted

Solution code:
human_num, time = tuple(int(i) for i in input().split(" "))
time_list = tuple(int(i) for i in input().split(" "))
ans = 0
for i in range(human_num):
    if i == 0:
        ans += time
    else:
        time_differance = time_list[i] - time_list[i - 1]
        if time_differance <= time:
            ans += time_differance
        else:
            ans += time
print(ans)

Submission status: Accepted

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

ans = 0

now = t_list[0]
end = now + t

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

ans += (end - now)

print(ans)

Submission status: Accepted

Solution code:
#ARC073C - Sentou
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
    ans += min(t, i - cur)
    cur = i
ans += t
print(ans)

Submission status: Accepted

Solution code:
#ARC073C - Sentou
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur, lim = 0, 0, 0
for i in lst:
    ans += t if i > lim else i - cur
    cur = i
    lim = cur + t
ans += lim - cur
print(ans)

Submission status: Accepted

Solution code:
N, T = map(int, input().split())
t = sorted(map(int, input().split()), reverse=True)

before = float("inf")
ans = 0
for i in t:
    ans += min(T, before - i)
    before = i
print(ans)

Submission status: Accepted

Solution code:

n, t = [ int(v) for v in input().split() ]
on_list = [ int(v) for v in input().split() ]

total = 0
part = t
for i in range(n-1):

	if on_list[i+1] > on_list[i] + t:
		total+= part
		part = t
	else:
		part += on_list[i+1] - on_list[i]
total+= part
print(total)

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
ts=list(map(int,input().split()))
time=0
t_=10**10
for i in range(n):
     t__=ts.pop()
     if t_-t__>t:
          time+=t
     else:
          time+=(t_-t__)
     t_=t__
print(time)

Submission status: Accepted

Solution code:
# coding: utf-8
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:
# 2019/05/31
# AtCoder Beginner Contest 073 - C

# For the answer:
# 累積和してTで飛ばしていく
# - 累積和しないで足し込めばいける気もする // 採用

# Input
n, t = map(int, input().split())
tl = list(map(int, input().split()))

et = t      ### Because  tl[0] == 0
tsum = t

for i in range(1, n):
    if tl[i] >= et:
        tsum += t
    else:
        tsum += tl[i] - tl[i - 1]
    et = tl[i] + t

# Output
print(tsum)

Submission status: Accepted

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

pre_t = t[0]
cnt = 0
for ti in t[1:]:
	cnt += min([T, ti - pre_t])
	pre_t = ti
cnt += T

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

f = None
p = None
ans = 0
for t in map(int, input().split()):
  if f is None:
    f = t
    p = f - T

  ans += T
  rest = p + T - (t - f)
  if rest > 0:
    ans -= rest
  p = t - f

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,k= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
s = k
for i in range(1,n):
    s+=min(k,a[i]-a[i-1])
print(s)

Submission status: Accepted

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

cnt = 0
for i in range(N-1):
  # print(i, A[i+1]-A[i], 10)
  cnt += min(T, A[i+1]-A[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(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:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

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

Submission status: Accepted

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

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

print(sum(L) + T)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, T = LI()
    ts = LI()
    ans = 0
    t0 = ts[0]
    for t in ts[1:]:
        ans += min(T, (t - t0))
        t0 = t
    ans += T
    return ans

print(main())