Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(h[i]-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(h[i]-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        a = min(k+1, n-i)
        for j in range(1, a):
            num = dp[i]+abs(h[i]-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        for j in range(1, min(k+1, n-i)):
            num0 = h[i]-h[i+j]
            if num0 < 0:
                num0 *= -1
            num = dp[i]+num0
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(h[i]-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(1, min(k+1, n-i)):
        dp[i+j] = min(dp[i]+abs(h[i]-h[i+j]), dp[i+j])
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()