Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,K = [int(e) for e in input().split()]
    asiba = [int(e) for e in input().split()]
    dp =[0] *N

    #初期化
    dp[0]=0
    dp[1]=abs(asiba[1]-asiba[0])

    for i in range(2,N):
        dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]) for j in range(1,min(i+1,K+1)))
    
    print(dp[N-1])
main()

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
cost = [0] * n
for i in range(1, n):
  cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
print(cost[n - 1])

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(e) for e in input().split()]
asiba = [int(e) for e in input().split()]
dp =[0] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(abs(asiba[i] - asiba[j]) + dp[j] for j in range(max(0, i - K), i))
    
print(dp[N-1])


Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = [int(e) for e in input().split()]
asiba = [int(e) for e in input().split()]
dp =[0] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
    
print(dp[N-1])


Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(e) for e in input().split()]
asiba = [int(e) for e in input().split()]
dp =[0] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]) for j in range(1,min(i+1,K+1)))
    
print(dp[N-1])

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
asiba = list(map(int,input().split()))
dp =[0] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]) for j in range(1,min(i+1,K+1)))
    
print(dp[N-1])

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
asiba = list(map(int,input().split()))
dp =[10**10] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]) for j in range(1,min(i+1,K+1)))
    
print(dp[N-1])

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
asiba = list(map(int,input().split()))
dp =[10**10] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]),dp[i] j in range(1,min(i+1,K+1)))
    
print(dp[N-1])

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
asiba = list(map(int,input().split()))
dp =[10**10] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]),dp[i])
print(dp[N-1])

Fixed submission:
def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()