Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [0] + list(map(int, input().split())) # index調整
dp = [0] * (n+1)

for i in range(2,n+1):
    start = max(1,i-k)
    dp[i] = min(list(map(lambda x,y:x+y, dp[start:i], list(map(lambda x:abs(h[i]-x), h[start:i])))))            
print(dp[n])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [0] + list(map(int, input().split())) # index調整
dp = [0] * (n+1)

for i in range(2,n+1):
    start = max(1,i-k)
    dp[i] = min(list(map(lambda x,y:x+y, dp[start:i], list(map(lambda x:abs(h[i]-x), h[start:i])))))            
print(dp[n])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])

Buggy python submission (verdict: Runtime Error):
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = max(1,i-k)
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i]))            
print(dp[n])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整

dp = np.array([1<<64] * (n+1))
dp[1] = 0

for i in range(2,n+1):
    for j in range(1,k+1):
        if i - j >= 1:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        else:
            break
            
print(dp[n])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0,0) #index調整

dp = [1<<64] * (n+1)
dp[1] = 0

for i in range(2,n+1):
    for j in range(1,k+1):
        if i - j >= 1:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        else:
            break
            
print(dp[n])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0,0) #index調整

dp = [1<<64] * (n+1)
dp[1] = 0

for i in range(2,n+1):
    for j in range(1,k+1):
        if i - j >= 1:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
            
print(dp[n])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])