Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i])
print(dp[-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(N)
def rec(n):
    if dp[n] == 0:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = 10**9
            for i in range(1, K+1):
                if n-i >= 0:
                    temp = rec(n-i)+abs(h[n-i]-h[n])
                    work = work if work<temp else temp
            dp[n] = work
    return dp[n]
print(int(rec(N-1)))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for i in range(N)]
def rec(n):
    if dp[n] == -1:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = 10**9
            for i in range(1, K+1):
                if n-i >= 0:
                    temp = rec(n-i)+abs(h[n-i]-h[n])
                    work = work if work<temp else temp
            dp[n] = work
    return dp[n]
print(rec(N-1))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for i in range(N)]
def rec(n):
    if dp[n] == -1:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = []
            for i in range(1, K+1):
                if n-i >= 0:
                    work.append(rec(n-i)+abs(h[n-i]-h[n]))
            dp[n] = min(work)
    return dp[n]
rec(N-1)
print(dp[N-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for i in range(N)]
def rec(n):
    if dp[n] == -1:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = []
            for i in range(1, K+1):
                if n-i >= 0:
                    work.append(rec(n-i)+abs(h[n-i]-h[n]))
            dp[n] = min(work)
    return dp[n]
rec(N-1)
print(dp[N-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for i in range(N)]
def rec(n):
    if dp[n] == -1:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = []
            for i in range(1, K+1):
                if n-i >= 0:
                    work.append(rec(n-i)+abs(h[n-i]-h[n]))
            dp[n] = min(work)
    return dp[n]
rec(N-1)
print(dp[N-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
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]+abs(h[s:i]-h[i]))
print(dp[-1])