Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
n,k = map(int,input().split())
h = list(map(int,sys.stdin.readline().split()))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))

print(dp[-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])

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

dp = [0] * n
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))

print(dp[-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])

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

dp = [0] * n
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))

print(dp[-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])

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

dp = [0] * n
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))

print(dp[n-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])

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

dp = [0] * (n)
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    x = max(i-k, 0)
    dp[i] = min([d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i])])

print(dp[n-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])

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

dp = [0] * (n)
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    minp = dp[i-1] + abs(h[i]-h[i-1])
    x = max(i-k, 0)
    dp[i] = min([d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i])])

print(dp[n-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])

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

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

        if i - j < 0:
            break;
        #print(i,j,minp,dp[i-j] + abs(h[i]-h[i-j]))
        minp = min(minp,
                dp[i-j] + abs(h[i]-h[i-j]))
    dp[i] = minp
#print(dp)
print(dp[n-1])


Fixed submission:
import sys
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,sys.stdin.readline().split())))

dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    x = max(i-k, 0)
    #dp[i] = min(d + abs(h[i]-hd) for d, hd in zip(dp[x:i], h[x:i]))
    dp[i] = (dp[x:i] + abs(h[i] - h[x:i])).min()
print(dp[-1])