Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    m = 1000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            if i == 3:
            m = min(m,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = m
print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):

n,k = map(int, input().split())
h = list(map(int,input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    ans = 10000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(tmp, ans)
    dp[i] = ans
# dp[2] = min((h[2] - h[1])+dp[1], (h[2]-h[0])+dp[0])
# dp[3] = min((h[3] - h[2])+dp[2], (h[3]-h[1])+dp[1], (h[3]-h[0])+dp[0])

print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
h = list(map(int, input().split()))
c = [0 for i in range(n)]
c[0] = 0
c[1] = abs(h[1] - h[0])
# c[2] = c[0] + abs(h[2]-h[0])
# c[2] = c[1] + abs(h[2]-h[1])
# c[3] = c[1] + abs(h[3]-h[1])
# c[3] = c[2] + abs(h[3]-h[1])
for i in range(2, n):
    # c[i] = min(c[i-1]+abs(h[i]-h[i-1]), c[i-2]+abs(h[i]-h[i-2]))
    c[i] = min(c[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k,i)+1))
print(c[-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])

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

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])

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


Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
# dp[2] = min(abs(h[2]-h[0]), dp[1]+abs(h[2]-h[1]))
# dp[3] = min((abs(h[3]-h[1])+dp[1]), abs(h[3]-h[2])+dp[2])
for i in range(2,n):
    ans = 10000000000000000000000000
    for j in range(1,k+1):
        if i-j >= 0:
            tmp = abs(h[i]-h[i-j])+dp[i-j]
            ans = min(ans,tmp)
    # dp[i] = min((abs(h[i]-h[i-2])+dp[i-2]), abs(h[i]-h[i-1])+dp[i-1])
    dp[i] = ans
print(dp[-1])