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

n, k = [int(elem) for elem in input().split()]
h = np.array(list(map(int, input().split())))

dp=np.full(n, 10**10)
dp[0] = 0
for i in range(0, n):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + np.abs(h[i] - h[i+j])
      if dp[i+j] > tmp:
          dp[i+j] = tmp
print(int(dp[-1]))

Fixed submission:
INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()

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

n, k = [int(elem) for elem in input().split()]
h = np.array(list(map(int, input().split())))

dp=np.full(n, 10**10)
dp[0] = 0
for i in range(0, n):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + abs(h[i] - h[i+j])
      if dp[i+j] > tmp:
          dp[i+j] = tmp
print(int(dp[-1]))

Fixed submission:
INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(elem) for elem in input().split()]
h = [int(elem) for elem in input().split()]

dp=[10**10]*n
dp[0] = 0
for i in range(0, n):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + abs(h[i] - h[i+j])
      if dp[i+j] > tmp:
          dp[i+j] = tmp
print(dp[-1])

Fixed submission:
INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(elem) for elem in input().split()]
h = [int(elem) for elem in input().split()]

dp=[0]*n
for i in range(0, n):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + abs(h[i] - h[i+j])
      if dp[i+j] == 0:
        dp[i+j] = tmp
      else:
        if dp[i+j] > tmp:
          dp[i+j] = tmp
print(dp[-1])

Fixed submission:
INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(elem) for elem in input().split()]
h = [int(elem) for elem in input().split()]

def calc_min(h, i, k, dp):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + abs(h[i] - h[i+j])
      if dp[i+j] == 0:
        dp[i+j] = tmp
      else:
        if dp[i+j] > tmp:
          dp[i+j] = tmp
  return dp

dp=[0]*n
for i in range(0, n):
  dp = calc_min(h, i, k, dp)

print(dp[-1])

Fixed submission:
INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()