Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    INF = 10**10
    #dp[i]　iの位置に到達する最小の値
    dp = [INF]*N
    dp[0] = 0
    for i in range(N):
        for k in range(1, K+1):
            if (i+k)<N:
                dp[i+k] = min(dp[i+k], dp[i] + abs(h[i+k]-h[i]))
    print(dp[N-1])

if __name__ == '__main__':
    main()

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]*N
for _ in range(1,N):
  Hi = H[_]
  DP[_] = min( [DP[j] + abs(Hi - H[j]) for j in range(max(0,_-K),_)])
print(DP[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]*(N+1)
for _ in range(2,N+1):
  Hi = H[i-1]
  DP[i] = min( [DP[j] + abs(Hi - H[j-1]) for j in range(max(1,i-K),i)])
print(DP[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  Hi = harr[i]
  dum = dp + np.abs(Hi - harr)
  dp[i]=min(dum[max(0,i-K):i])
print(dp[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
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
for i in range(1,N):
  Hi = H[i]
  DP[i] = min( [DP[j] + abs(Hi - H[j]) for j in range(max(0,i-K),i)])
print(DP[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
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+1)
for i in range(2,N+1):
  Hi = H[i-1]
  DP[i] = min( [DP[j] + abs(Hi - H[j-1]) for j in range(max(1,i-K),i)])
print(DP[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]*N
for i in range(1,N):
  DP[i] = min( [DP[j] + abs(H[i] - H[j]) for j in range(max(1,i-K),i)])
print(DP[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
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+1)
for i in range(2,N+1):
  DP[i] = min( [DP[j] + abs(H[i-1] - H[j-1]) for j in range(max(1,i-K),i)])
print(DP[-1])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
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+1)
def dH(i,j):
  return abs(H[i-1] - H[j-1])
for i in range(2,N+1):
  DP[i] = min( [DP[j] + dH(j, i) for j in range(max(1,i-K),i)])
print(DP[N])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]*(N+1)
def dH(i,j):
  return abs(H[i-1] - H[j-1])
for i in range(2,N+1):
  DP[i] = DP[i-1] + dH(i-1, i)
  for j in range(2,K+1):
    jc = DP[i-j] + dH(i-j, i)
    if (i-j)>=1 and jc < DP[i]:
      DP[i] = jc
print(DP[N])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]*(N+1)  #DP[i] iに来るための最小コスト
def dH(i,j):
  return abs(H[i-1] - H[j-1])
for i in range(2,N+1):
  DP[i] = DP[i-1] + dH(i-1, i)
  for j in range(2,min(K+1,i+1):
      DP[i] = min( DP[i], DP[i-j] + dH(i-j, i) )
print(DP[N])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
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+1)  #DP[i] iに来るための最小コスト
def dH(i,j):
  return abs(H[i-1] - H[j-1])
for i in range(2,N+1):
  DP[i] = DP[i-1] + dH(i-1, i)
  for j in range(2,K+1):
    if (i-j)>=1:
      DP[i] = min( DP[i], DP[i-j] + dH(i-j, i) )
print(DP[N])

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))
import numpy as np
dp = np.zeros(N,dtype=np.int)
harr = np.array(H)
for i in range(1,N):
  St = max(0,i-K)
  Hi = harr[i]
  dp[i] = min(dp[max(0,i-K):i] + np.abs(Hi - harr[max(0,i-K):i]))
print(dp[-1])