Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Educational DP Contest
# B Frog 2


def main():
    n, k, *h = map(int, open(0).read().split())

    dp = [0 for _ in range(n)]
    l = [0 if i - k < 0 else i - k for i in range(n)]
    for i, (h_now, l_now) in enumerate(zip(h[1:], l[1:]), 1):
        hs = h[l_now:i]
        dps = dp[l_now:i]
        f = lambda x, y: abs(h_now - x) + y
        *tmp, = map(f, hs, dps)
        tmp.sort()
        dp[i] = tmp[0]

    res = dp[-1]
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Educational DP Contest
# B Frog 2


def main():
    n, k, *h = map(int, open(0).read().split())

    dp = [0 for _ in range(n)]
    l = [0 if i - k < 0 else i - k for i in range(n)]
    for i, (h_now, l_now) in enumerate(zip(h[1:], l[1:]), 1):
        hs = h[l_now:i]
        dps = dp[l_now:i]
        f = lambda x, y: abs(h_now - x) + y
        *tmp, = map(f, hs, dps)
        dp[i] = min(tmp)

    res = dp[-1]
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Educational DP Contest
# B Frog 2


def main():
    n, k, *h = map(int, open(0).read().split())

    dp = [0 for _ in range(n)]
    for i, h_now in enumerate(h[1:], 1):
        l = max(0, i - k)
        hs = h[l:i]
        dps = dp[l:i]
        tmp = 10 ** 9
        for x, y in zip(hs, dps):
            cost = abs(h_now - x) + y
            tmp = min(tmp, cost)
        dp[i] = tmp

    res = dp[-1]
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Educational DP Contest
# B Frog 2


def main():
    n, k, *h = map(int, open(0).read().split())

    DP = [0 for _ in range(n)]
    for i, h_now in enumerate(h[1:], 1):
        l = max(0, i - k)
        hs = h[l:i]
        DPs = DP[l:i]
        tmp = []
        for x, y in zip(hs, DPs):
            cost = abs(h_now - x) + y
            tmp.append(cost)
        DP[i] = min(tmp)

    res = DP[-1]
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(m[-1])

Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k=map(int,input().split())
h=np.array(list(map(int,input().split())))
c=np.zeros(n,dtype=int)
for i in range(1,n):
  c[i]=np.min(np.array([abs(h[i]-h[i-j])+c[i-j] for j in range(1,k+1) if i-j>=0]))
print(c[n-1])

Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
h=np.array(map(int,input().split()))
c=[0]*n
for i in range(1,n):
  hn=h[i]
  c[i]=np.min(np.array([abs(h[i]-h[i-j])+c[i-j] for j in range(1,k+1) if i-j>=0]))
print(c[n-1])

Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-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):
  c[i]=min(set(abs(h[i]-h[i-j])+c[i-j] for j in range(1,k+1) if i-j>=0))
print(c[n-1])

Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-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):
  hn=h[i]
  c[i]=min([ abs(h[i]-h[i-j])+c[i-j] for j in range(1,k+1) if i-j>=0])
print(c[n-1])

Fixed submission:
n, k = map(int, input().split())
hs = list(map(int, input().split()))
dp=[0]*n
dp[0]=0
for i, hi in enumerate(hs):
    if i == 0:
        continue
    s = max(0, i-k)
    dp[i] = min([ml + abs(hl - hi) for ml, hl in zip(dp[s:i], hs[s:i])])
print(dp[-1])