Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i in range(2, n):
    di = 10**9
    hi = h[i]
    for j in range(max(0, i-k), i):
        dj = dp[j] + abs(h[j]-hi)
        if di > dj:
            di = dj
    dp[i] = di
print(dp[-1])

Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i, hi in enumerate(h[2:], 2):
  di = 10**9
  m = i-k if i>k else 0
  for j in range(m, i):
    dj = dp[j] + abs(h[j]-hi)
    if di > dj:
      di = dj
    dp[i] = di
print(dp[-1])

Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i, hi in enumerate(h[2:], 2):
    di = 10**9
    m = i-k if i>k else 0
    for dj, hj in zip(dp[m:i], h[m:i]):
        d = dj + abs(hj-hi)
        if di > d:
            di = d
    dp[i] = di
print(dp[-1])

Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
m = [0 if i-k<0 else i-k for i in range(2, n)]
for i, (hi, mi) in enumerate(zip(h[2:], m), 2):
    di = 10**9
    for dj, hj in zip(dp[mi:i], h[mi:i]):
        d = dj + abs(hj-hi)
        if di > d:
            di = d
    dp[i] = di
print(dp[-1])

Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i in range(2, n):
    di = 10**9
    hi = h[i]
    for j in range(max(0, i-k), i):
        dj = dp[j] + abs(h[j]-hi)
        if di > dj:
            di = dj
    dp[i] = di
print(dp[-1])

Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**10
dp = [inf]*n
dp[0] = 0
for i in range(1, n):
    di = dp[i]
    hi = h[i]
    for k in range(max(i-K, 0), i):
        a = dp[k]+abs(hi-h[k])
        if di > a:
            di = a
    dp[i] = di
print(dp[n-1])

Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

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


Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()

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


Fixed submission:
def main():
    n, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = 10**10
    dp = [inf]*n
    dp[0] = 0
    for i, (di, hi) in enumerate(zip(dp[1:], h[1:]), 1):
        num = max(i-K, 0)
        for dk, hk in zip(dp[num:i], h[num:i]):
            a = dk+abs(hi-hk)
            if di > a:
                di = a
        dp[i] = di
    print(dp[n-1])

if __name__ == "__main__":
    main()