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

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

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

print(dp[n - 1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])

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

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

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

print(dp[n - 1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])

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

dp = [10 ** 9 + 7] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == 10 ** 9 + 7:
                dp[i + j] = dp[i] + abs(h[i] - h[i + j])
            else:    
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
        else:
            break
        
print(dp[n - 1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9 + 7] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(k + 1):
        if dp[i + j] == 10 ** 9 + 7:
            dp[i + j] = dp[i] + abs(h[i] - h[i - j])
        else:    
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - dp[i + j]))

print(dp[n - 1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * 10 ** 5
h = h + [INF] * 10 ** 5

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

print(dp[n - 1])


Fixed submission:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])