Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
if n-1 <= k:
    print(abs(h[-1]-h[0]))
else:
    for i in range(1,k+1):
        dp[i] = abs(h[i]-h[0])
    for i in range(k+1,n): 
        for j in range(1,k+1):
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
    print(dp[-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = np.array([10**10]*(n))
dp[0] = 0
if n-1 <= k:
    print(abs(h[-1]-h[0]))
else:
    for i in range(1,k+1):
        dp[i] = abs(h[i]-h[0])
    for i in range(k+1,n): 
        for j in range(1,k+1):
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
    print(dp[-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = np.array([10**10]*(n))
dp[0] = 0
if n-1 <= k:
    print(abs(h[-1]-h[0]))
else:
    for i in range(1,k+1):
        dp[i] = abs(h[i]-h[0])
    for i in range(k+1,n): 
        for j in range(1,k+1):
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
    print(dp[-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = np.array([10**10]*(n))
dp[0] = 0
if n-1 <= k:
    print(abs(h[-1]-h[0]))
else:
    for i in range(1,k+1):
        dp[i] = abs(h[i]-h[0])
    for i in range(k+1,n): 
        for j in range(1,k+1):
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
    print(dp[-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))

ans = [0]*n
ans[1] = abs(h[1]-h[0])

for i in range(2,n):
    ans[i] = min(abs(h[i]-h[j]) + ans[j] for j in range(max(0,i-k),i))
print(ans[n-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))
a = [0]*n
if k > n:
    k = n
for i in range(1,n):
    a[i] = float('inf')
    for j in range(1,min(k+1,i+1)):
        a[i] = min(a[i], a[i-j] + abs(h[i]-h[i-j]) )
print(a[n-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))
a = [0]*n
if k > n:
    k = n
for i in range(1,k):
    a[i] = float('inf')
    for j in range(1,i+1):
        a[i] = min(a[i], a[i-j] + abs(h[i]-h[i-j]))
for i in range(k,n):
    a[i] = float('inf')
    for j in range(1,k+1):
        a[i] = min(a[i], a[i-j] + abs(h[i]-h[i-j]) )
print(a[n-1])

Fixed submission:
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])