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

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()

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

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k, *h = map(int, open(0).read().split())
dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
    min_i = max(0, i-k)
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
print(dp[n-1])

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()

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

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()

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

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
n, k, *h = map(int, open(0).read().split())
dp = [math.inf] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(0, i-k), i):
        dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i])
print(dp[n-1])

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(1, n):
        min_i = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_i, i)])
    print(dp[n-1])
if __name__ == '__main__':
    main()