Buggy python submission (verdict: Runtime Error):
import numba


@numba.jit
def main(n,k,h):
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(n):
        for j in range(1, min(k, n - i - 1) + 1):
            dp[i + j] = min(
                dp[i + j],
                dp[i] + abs(h[i] - h[i + j]) )
    print(dp[-1])


if __name__ == "__main__":
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    main(n,k,h)


Fixed submission:
import numpy as np


def main():
    n, k = map(int, input().split())
    height = np.fromstring(input(), 'int32', sep=' ')
    height = np.append(height, [0] * (k - 1))

    dp = np.full((n + k - 1), 10 ** 9, dtype='int')
    dp[0] = 0

    for i in range(n - 1):
        default_val = dp[i + 1:i + 1 + k]
        new_val = dp[i] + np.abs(height[i + 1:i + 1 + k] - height[i])
        dp[i + 1:i + 1 + k] = np.minimum(default_val, new_val)
    print(dp[n - 1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    # dp = [float('inf')] * n
    dp = np.full(n, float('inf'))
    dp[0] = 0
    for i in range(n):
        for j in range(1, min(k, n - i - 1) + 1):
            dp[i + j] = min(
                dp[i + j],
                dp[i] + abs(h[i] - h[i + j]) )
    print(int(dp[-1]))


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np


def main():
    n, k = map(int, input().split())
    height = np.fromstring(input(), 'int32', sep=' ')
    height = np.append(height, [0] * (k - 1))

    dp = np.full((n + k - 1), 10 ** 9, dtype='int')
    dp[0] = 0

    for i in range(n - 1):
        default_val = dp[i + 1:i + 1 + k]
        new_val = dp[i] + np.abs(height[i + 1:i + 1 + k] - height[i])
        dp[i + 1:i + 1 + k] = np.minimum(default_val, new_val)
    print(dp[n - 1])


if __name__ == "__main__":
    main()

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

    # dp = [float('inf')] * n
    dp = np.full(n, float('inf'))
    dp[0] = 0
    for i in range(n):
        for j in range(1, min(k, n - i - 1) + 1):
            dp[i + j] = min(
                dp[i + j],
                dp[i] + abs(h[i] - h[i + j]) )
    print(int(dp[-1]))


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np


def main():
    n, k = map(int, input().split())
    height = np.fromstring(input(), 'int32', sep=' ')
    height = np.append(height, [0] * (k - 1))

    dp = np.full((n + k - 1), 10 ** 9, dtype='int')
    dp[0] = 0

    for i in range(n - 1):
        default_val = dp[i + 1:i + 1 + k]
        new_val = dp[i] + np.abs(height[i + 1:i + 1 + k] - height[i])
        dp[i + 1:i + 1 + k] = np.minimum(default_val, new_val)
    print(dp[n - 1])


if __name__ == "__main__":
    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, n - i - 1) + 1):
            dp[i + j] = min(
                dp[i + j],
                dp[i] + abs(h[i] - h[i + j]) )
    print(int(dp[-1]))


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np


def main():
    n, k = map(int, input().split())
    height = np.fromstring(input(), 'int32', sep=' ')
    height = np.append(height, [0] * (k - 1))

    dp = np.full((n + k - 1), 10 ** 9, dtype='int')
    dp[0] = 0

    for i in range(n - 1):
        default_val = dp[i + 1:i + 1 + k]
        new_val = dp[i] + np.abs(height[i + 1:i + 1 + k] - height[i])
        dp[i + 1:i + 1 + k] = np.minimum(default_val, new_val)
    print(dp[n - 1])


if __name__ == "__main__":
    main()

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

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


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np


def main():
    n, k = map(int, input().split())
    height = np.fromstring(input(), 'int32', sep=' ')
    height = np.append(height, [0] * (k - 1))

    dp = np.full((n + k - 1), 10 ** 9, dtype='int')
    dp[0] = 0

    for i in range(n - 1):
        default_val = dp[i + 1:i + 1 + k]
        new_val = dp[i] + np.abs(height[i + 1:i + 1 + k] - height[i])
        dp[i + 1:i + 1 + k] = np.minimum(default_val, new_val)
    print(dp[n - 1])


if __name__ == "__main__":
    main()