Buggy python submission (verdict: Time Limit Exceeded):
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i in range(1,N):
    dp[i] = min( [ dp[i-j] + abs( H[i] - H[i-j] ) for j in range(1,min(K+1,i+1)) ] )
print(dp[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [float("inf")]*N
dp[0] = 0
for i in range(1,N):
    dp[i] = min( [ dp[i-j] + abs( H[i] - H[i-j] ) for j in range(1,min(K+1,i+1)) ] )
print(dp[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
H.append(0)
dp = [float("inf")]*N
dp[0] = 0
for i in range(N):
    for j in range(1,min(K+1,N-i)):
        dp[i+j] = min(dp[i+j], dp[i] + abs( H[i+j] - H[i] ) )
print(dp[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map( int, input().split() )
h_list = list( map( int, input().split() ) )
h_list.append(0)
result_list = [float("inf")]*N
result_list[0] = 0
for i in range(N):
    for j in range(1,min(K+1,N-i)):
        result_list[i+j] = min(result_list[i+j], result_list[i] + abs( ( h_list[i+j] - h_list[i]) ) )
print(result_list[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map( int, input().split() )
h_list = list( map( int, input().split() ) )
h_list.append(0)
result_list = [10**10]*N
result_list[0] = 0
for i in range(N):
    for j in range(1,min(K+1,N-i)):
        result_list[i+j] = min(result_list[i+j], result_list[i] + abs( ( h_list[i+j] - h_list[i]) ) )
print(result_list[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,K = map( int, input().split() )
h_list = list ( map( int, input().split() ) )
for i in range(150):
    h_list.append(0)
h_list = np.array(h_list)
result_list = np.array([10**10]*(N+150))
result_list[0] = 0
for i in range(N):
    for j in range(1,K+1):
        result_list[i+j] = min(result_list[i+j], result_list[i] + abs( ( h_list[i+j] - h_list[i]) ) )
print(result_list[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map( int, input().split() )
h_list = list( map( int, input().split() ) )
for i in range(150):
    h_list.append(0)
result_list = [10**10]*(N+150)
result_list[0] = 0
for i in range(N):
    for j in range(1,K+1):
        result_list[i+j] = min(result_list[i+j], result_list[i] + abs( ( h_list[i+j] - h_list[i]) ) )
print(result_list[N-1])

Fixed submission:
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])