Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k = map(int,input().split())
ary = np.array(list(map(int,input().split())))
dp = np.zeros(n)
for i in range(1,n):
    a = max(0,i-k)
    dp[i] = min(dp[a:i]+np.abs(ary[i]-ary[a:i]))
print(int(dp[n-1]))

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k = map(int,input().split())
ary = np.array(list(map(int,input().split())))
dp = np.array([np.inf for _ in range(n)])
dp[0]=0
for i in range(1,n):
    a = max(0,i-k)
    dp[i] = min(dp[a:i]+np.abs(ary[i]-ary[a:i]))
print(int(dp[n-1]))

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
sys.setrecursionlimit(500000)

def f(i):
    if memo[i] != float("Inf"):return memo[i]

    for j in range(1,k+1):
        if i - j >= 0:
            memo[i] = min(memo[i],f(i-j)+abs(ary[i-j]-ary[i]))
    return memo[i]
n,k = map(int,input().split())
ary = list(map(int,input().split()))
ary = np.array(ary)
memo = np.array([np.inf for _ in range(n)])
memo[0] = 0
print(int(f(n-1)))

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(500000)

def f(i):
    if memo[i] != float("Inf"):return memo[i]

    for j in range(1,k+1):
        if i - j >= 0:
            memo[i] = min(memo[i],f(i-j)+abs(ary[i-j]-ary[i]))
    return memo[i]
n,k = map(int,input().split())
ary = list(map(int,input().split()))
memo = [float("Inf") for _ in range(n)]
memo[0] = 0
print(f(n-1))

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(500000)

def f(i):
    if memo[i] != float("Inf"):return memo[i]

    for j in range(1,k+1):
        if i - j >= 0:
            memo[i] = min(memo[i],f(i-j)+abs(ary[i-j]-ary[i]))
    return memo[i]
n,k = map(int,input().split())
ary = list(map(int,input().split()))
memo = [float("Inf") for _ in range(n)]
memo[0] = 0
print(f(n-1))

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
nums, jump = list(map(int, input().split()))
height = list(map(int,input().split()))
dp = [0 for i in range(nums)]

for i in range(1,nums):
    c = float("inf")
    for x in range(1,jump+1):
        if i-x < 0: continue
        check = dp[i-x] + abs(height[i-x] - height[i])
        if check < c:
            c = check
            dp[i] = c

print(dp[nums-1])

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
def chmin(a, b):
    if b < a:
        a = b
    return a

nums, jump = list(map(int, input().split()))
height = list(map(int,input().split()))
dp = [0 for i in range(nums)]
for i in range(nums):dp[i] = float("inf")
dp[0] = 0

for i in range(nums):
    for x in range(1,jump+1):
        if i+x >= nums: continue
        dp[i+x] = chmin(dp[i+x],dp[i] + abs(height[i] - height[i+x]))

print(dp[nums-1])

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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

Buggy python submission (verdict: Time Limit Exceeded):
nums, jump = list(map(int,input().split()))
height = list(map(int,input().split()))
dp = [0 for i in range(nums)]
for i in range(nums):dp[i] = float("inf")
dp[0] = 0
for i in range(nums):
    for x in range(1,jump+1):
        if i+x >= nums: continue
        check = dp[i] + abs(height[i] - height[i+x])
        if check < dp[i+x]:
            dp[i+x] = check
print(dp[nums-1])

Fixed submission:
import numpy as np

n, k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)
dp = np.zeros(n, dtype=int)

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