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


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])

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


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])

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


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])

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


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])

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

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])

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

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])