Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n in range(1, N):
    l = max(0, n - K)
    dp[n] = min(abs(A[n] - a) + d for a, d in zip(A[l : n], dp[l : n]))

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n in range(1, N):
    l = min(n, K)
    dp[n] = min(abs(A[n] - A[n - k]) + dp[n - k] for k in range(1, l + 1))

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        dp[n] = min(min(abs(A[n] - A[n - k]) + dp[n - k], min_num) for k in range(1, l + 1))

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = []
for n in range(N):
    if n == 0:
        dp.append(0)
    else:
        l = min(n, K)
        min_num = 10 ** 10
        dp.append(min([min(abs(A[n] - A[n - k]) + dp[n - k], min_num) for k in range(1, l + 1)]))

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        dp[n] = min([min(abs(A[n] - A[n - k]) + dp[n - k], min_num) for k in range(1, l + 1)])

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        min_num = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        for k in range(1, l + 1):
            min_num = min(abs(A[n] - A[n - k]) + dp[n - k], min_num)
    dp[n] = min_num

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

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

N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        min_num = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        for k in range(1, l + 1):
            min_num = min(abs(A[n] - A[n - k]) + dp[n - k], min_num)
    dp[n] = min_num

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, ().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        min_num = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        for k in range(1, l + 1):
            min_num = min(abs(A[n] - A[n - k]) + dp[n - k], min_num)
    dp[n] = min_num

print(dp[-1])


Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
N, K = map(int, input().split())
A = numpy.array(list(map(int, input().split())))

dp = numpy.zeros(N, dtype=int)
for n in range(N):
    if n == 0:
        min_num = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        for k in range(1, l + 1):
            min_num = min(abs(A[n] - A[n - k]) + dp[n - k], min_num)
    dp[n] = min_num

print(dp[-1])

Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        min_num = 0
    else:
        l = min(n, K)
        min_num = 10 ** 10
        for k in range(1, l + 1):
            min_num = min(abs(A[n] - A[n - k]) + dp[n - k], min_num)
    dp[n] = min_num

print(dp[-1])

Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [None] * N
for n in range(N):
    if n == 0:
        dp[n] = 0
    elif n <= K:
        dp[n] = min([abs(A[n] - A[n - k - 1]) + dp[n - k - 1] for k in range(n)])
    else:        
        dp[n] = min([abs(A[n] - A[n - k - 1]) + dp[n - k - 1] for k in range(K)])
print(dp[-1])

Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [-1] * N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        dp[n] = min([abs(A[n] - A[n - k - 1]) + dp[n - k - 1] for k in range(min(K, n))])
print(dp[-1])

Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

dp = [0] + [None] * (N - 1)
for n, a in enumerate(A):
    if n:
        l = max(0, n - K)
        dp[n] = min(abs(a - a2) + d for a2, d in zip(A[l : n], dp[l : n]))

print(dp[-1])