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: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

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

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

    t = i_list()

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



if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
m=a*b
for i in range(a-1):
  if c[i+1]-c[i]<b:
    m=m-(b-(c[i+1]-c[i]))
print(m+b)

Submission status: Wrong Answer

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

total = n * t
short = 0
time = 0
for i in arr[1:]:
    if i - time >= t: continue
    short = abs(t - (i - time))
    total -= short
    time = i

print(total)

Submission status: Wrong Answer

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

ans = 0
for i in t:
    if i <= ans:
        ans -= ans - i
    ans += T

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
now = 0
step = False

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

print(ans)

Submission status: Wrong Answer

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 = 0
    for n in range(N - 1):
        ret += min(T[n + 1] - T[n], K)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def index(s,t,T):
    for i in range(s,len(t)):
        if t[s] + T < t[i]:
            return i
        if i == len(t) - 1:
            return i+1

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

    while True:
        index_ = index(s,t,T)
        ans += t[index_ - 1] + T - t[s]
        s = index_
        if index_ == len(t):
            break

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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])
ans+=a[-1]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sum_time = 0

for ti in t_list:
  if t > ti:
    sum_time += ti
  else:
    sum_time += t

print(sum_time+t)

Submission status: Wrong Answer

Solution code:
n,t = map(int,input().split())
ls = list(map(int,input().split()))
f = t
p = t
out = 0
y = lambda x : x - p
for i in ls:
    if f >= i:
        f = i + p
    else:
        out += f
        ls = list(map(y,ls))
        f = p
print(f+out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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()
t = IL()

ans = 0
for x in t[1:]:
  ans += min(x,T)
P(ans+T)

Submission status: Wrong Answer

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

# hot_wa = 0
# time = 0
# 
# for n in range(N):
#     time += T
#     if t[n] < time:
#         hot_wa = t[n]
#     else:
#         hot_wa += T
# 
#     time = t[n]
# print(hot_wa + T)


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

print(ans)

Submission status: Wrong Answer

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

hot_wa = 0
time = 0

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

Submission status: Wrong Answer

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

hot_wa = 0
time = 0

for n in range(1, N):
    time += T
    if t[n] <= time:
        hot_wa = t[n]
        time = t[n]
    else:
        hot_wa += T
        time = T

print(hot_wa + T)

Submission status: Wrong Answer

Solution code:
n,t = map(int,input().split())
T = list(map(int,input().split()))
U = []
for i in range(n):
  for j in range(t):
    a = T[i] + j+1
    U.append(a)
sT = set(T)
sU = set(U)
ans = sT | sU

print(len(ans))

Submission status: Wrong Answer

Solution code:
n,t = map(int,input().split())
T = list(map(int,input().split()))
U = []
for i in range(n):
  for j in range(t):
    a = T[i] + j+1
    U.append(a)
sT = set(T)
sU = set(U)
ans = set(T) | set(U)

print(len(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

total = [0]*n
total[0] = t
for i in range(1, n):
  if l[i] - l[i-1] < t:
    total[i] += l[i] + t
  else:
    total[i] += total[i-1] + t
    
print(total[-1])

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans+T)

Submission status: Wrong Answer

Solution code:
def solve(n, t, t_list):
    total = t
    prev = t_list[0]
    for i in t_list[1:]:
        if total - i > 0:
            total += i - prev
        else:
            total += t
        prev = i
    return total

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, t = map(int, list(input().split(' ')))
ti = list(map(int, list(input().split(' '))))
result = 10

for i, item in enumerate(ti):
  temp = t
  if i == len(ti) - 1:
    break
  if ti[i+1] - ti[i] < t:
    temp = ti[i+1] - ti[i]
  result = result + temp

print(result)

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
s = 0
end = 0

for i in range(n):
  if (L[i] + t) > end:
    s += (L[i] + t - end)
  end = (L[i] + t)
print(s)

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])

ri = 0
le = 10 ** 10
sum = 0

for x,y in L:
  if ri > x:
    sum += y - sum
    ri = y
  else:
    sum += b
    ri = y

print(sum)

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

from operator import mul
from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


# import random
# import time
# import entrypoints
n, t = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
# aa = [a[0]] + [(a[i+1] + a[i]) for i in range(0, n - 1)]
# eprint("aa ", end=": ")
# eprint(aa)
# aa = []
# aa.append(a[0])
# for i in range(1, n):
#     aa.append(a[i] + aa[i - 1])
a.append(sys.maxsize)
eprint("aa ", end=": ")
eprint(a)

ans = 0
first_flag = 1
continuous_flag = 0
l_continuous = []
l_distinct = []
for i in range(n):
    if a[i] + t >= a[i + 1]:
        if not (i in l_continuous):
            l_continuous.append(i)
        if a[i + 1] != sys.maxsize and not ((i + 1) in l_continuous):
            l_continuous.append(i + 1)
    else:
        if not (i in l_continuous):
            l_distinct.append(i)
eprint("l_continuous ", end=": ")
eprint(l_continuous)
eprint("l_distinct ", end=": ")
eprint(l_distinct)
i_start = 0
i_end = 0
for i in l_continuous:
    first_flag = 1
    if ((i in l_continuous) and ((i + 1) in l_continuous)):
        if first_flag == 1:
            i_start = 0
    else:
        i_end = i
        ans += a[i_end] - a[i_start] + t

for i in l_distinct:
    ans += t

print(ans)

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
answer = T

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

print(answer)

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
answer = T

for i in range(N):
    if t[i-1] + T > t[i]:
        answer = t[i] + T
    else:
        answer += T
    # if t[i] + T > t[i+1]:   # 重なっているとき
    #     answer = t[i+1] + T
    # elif t[i] + T <= t[i+1] and i == N-2:
        
    # else:                   # 離れているとき
    #     answer += T
    # # print(t[i])    
    # print(answer)

print(answer)

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
t = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
answer = 0
for i in range(N):
    if t[i-1] + T > t[i]:
        answer = t[i] + T
    else:
        answer += T
    # print(answer)

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N, T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
ans = 0
for i in t:
    ans += min(i, T)
print(ans + T)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0
a = [0]*10000
for i in range(n):
    start=t[i]
    end=start+T
    a[start:end]=[1 for i in range(T)]
print(a.count(1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

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

ans = 0

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

print(ans+T)

Submission status: Wrong Answer

Solution code:

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

s = tl[0]
ans = s + T

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

print(ans)

Submission status: Wrong Answer

Solution code:

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

s = tl[0]
ans = s + T

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(total)

Submission status: Wrong Answer

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

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

print(total)

Submission status: Wrong Answer

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

total = 0
for i in time:
    if i == 0:
        total += t
    elif t - i >=0:
        total += i

    else:
        total += t

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

t = [int(i) for i in input().split()]

ans = T
#tmp = T

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

Submission status: Wrong Answer

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,t[i+1]-t[i])
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, T = map(int, input().split())
L = [int(v) for v in input().split()]

ans = 0
pos = 0
for i in range(N):
    v = L[i]
    if pos > v:
        ans += v + T - ans
    else:
        ans += T

    pos = v + T

print(ans)

Submission status: Wrong Answer

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

ans = T
tmp = 0

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

print(ans)

Submission status: Wrong Answer

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

ans = T
tmp = 0

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

print(ans)

Submission status: Wrong Answer

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

for i in range(len(t)):
	if time + T > t[i]:
		t_.append(t[i])
		continue
	elif time + T == t[i]:
		time = t[i]
		t_.append(t[i])
		continue
	else:
		time = t[i]
		t_.append(-1)
		t_.append(t[i])
		continue
t_.append(-1)

target = list()
for i in range(len(t_)):
	if t_[i] != -1:
		target.append(t_[i])
	else:
		ans_time += abs(target[-1]-target[0])+T
		target = list()

print(ans_time)

Submission status: Wrong Answer

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

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

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
N, T = map(int, input().split())
t = list(map(int, input().split()))
res = 0
i = 0
while i < N:
  #print(res)
  ind = bl(t, t[i] + T)
  if ind == i + 1:
    res += T
    i += 1
  else:
    if ind == N and i != N - 1:
      res += t[-1] + T
      break
    elif ind > i + 1:
      if t[ind] == t[i] + T:
        res += t[ind] - t[i]
        i = ind
      else:
        res += t[ind - 1] - t[i]
        i = ind - 1
    else:
      res += T
      i = ind
print(res)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
N, T = map(int, input().split())
t = list(map(int, input().split()))
res = 0
i = 0
while i < N:
  ind = bl(t, t[i] + T)
  if ind == i + 1:
    res += T
    i += 1
  else:
    if ind == N and i != N - 1:
      res += t[-1] + T
      break
    elif ind > i + 1:
      res += t[ind - 1] - t[i]
      i = ind - 1
    else:
      res += T
      i = ind
print(res)

Submission status: Wrong Answer

Solution code:
n,t = map(int,input().split())
lst = [int(i) for i in input().split()]
lst.sort()
time = 0
for i in range(n):
    if time <= lst[i]:
        time += t
    else:
        time += t - (time - lst[i])

print(time)

Submission status: Wrong Answer

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

time = 0
for i in range(n):
    if time <= lst[i]:
        time += t
    else:
        time += t - (time - lst[i])

print(time)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
ans = 0
switches = list(map(int, input().split()))
switches.append(10**9+10)
for idx in range(N):
  ans += min(K, switches[idx+1] - switches[idx])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main(N, T, t):
    ttl = 0
    tmp = T
    for i in range(1, N):
        if(tmp<t[i]):
            ttl += T
        else:
            tmp = t[i] + T
    print(ttl+tmp)
          
if __name__ == '__main__':
    N, T = map(int, input().split())
    t = [int(i) for i in input().split()]
    
    main(N, T, t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if N == 1:
    print(T)
    exit()

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

ans += T
print(ans)