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

#import numpy as np

#a=np.array(h)
b=[[0 for i in range(n)] for j in range(n)]
#b=np.array(b)

for j in range(n):
    for i in range(n):
        if j>i:
            b[j][i]=abs(h[j]-h[i])
#print(b)

dp=[int(0) for i in range(n)]
dp0=[[10000000000 for i in range(n)] for j in range(n)]

dp0[0]=0
dp[0]=0

dp0[1]=b[1][0]
dp[1]=dp0[1]

if k==1:
    for i in range(2,n):
        dp[i]=dp[i-1]+b[i][i-1]
    
if k > 1:
    for j in range(2,n):
        if j <=k:
            for i in range(j):
                dp0[j][i]=dp[i]+b[j][i]
            dp[j]=min(dp0[j])
        else:
            for i in range(k):
                dp0[j][i+j-k]=dp[i+j-k]+b[j][i+j-k]
            dp[j]=min(dp0[j])

#print(dp0)
print(dp[n-1])

Fixed submission:
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

print(dp[-1])

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

#import numpy as np

#a=np.array(h)
b=[[0 for i in range(n)] for j in range(n)]
#b=np.array(b)

for j in range(n):
    for i in range(n):
        if j>i:
            b[j][i]=abs(h[j]-h[i])
#print(b)

dp=[int(0) for i in range(n)]
dp0=[[10000000000 for i in range(n)] for j in range(n)]

dp0[0]=0
dp[0]=0

dp0[1]=b[1][0]
dp[1]=dp0[1]

if k==1:
    for i in range(2,n):
        dp[i]=dp[i-1]+b[i][i-1]
    
if k > 1:
    for j in range(2,n):
        if j <=k:
            for i in range(j):
                dp0[j][i]=dp[i]+b[j][i]
            dp[j]=min(dp0[j])
        else:
            for i in range(k):
                dp0[j][i+j-k]=dp[i+j-k]+b[j][i+j-k]
            dp[j]=min(dp0[j])

#print(dp0)
print(dp[n-1])

Fixed submission:
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
#import numpy as np

n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]



a=np.array(h)
b=[[0 for i in range(n)] for j in range(n)]
b=np.array(b)

for j in range(n):
    for i in range(n):
        if j>i:
            b[j][i]=abs(a[j]-a[i])
#print(b)

dp=[int(0) for i in range(n)]
dp0=[[1000000000000000 for i in range(n)] for j in range(n)]

dp0[0]=0
dp[0]=0

dp0[1]=b[1][0]
dp[1]=dp0[1]

if k==1:
    for i in range(2,n):
        dp[i]=dp[i-1]+b[i][i-1]
    
if k > 1:
    for j in range(2,n):
        if j <=k:
            for i in range(j):
                dp0[j][i]=dp[i]+b[j][i]
            dp[j]=min(dp0[j])
        else:
            for i in range(k):
                dp0[j][i+j-k]=dp[i+j-k]+b[j][i+j-k]
            dp[j]=min(dp0[j])

#print(dp0)
print(dp[n-1])

Fixed submission:
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]

import numpy as np

a=np.array(h)
b=[[0 for i in range(n)] for j in range(n)]
b=np.array(b)

for j in range(n):
    for i in range(n):
        if j>i:
            b[j][i]=abs(a[j]-a[i])
#print(b)

dp=[int(0) for i in range(n)]
dp0=[[100000000000 for i in range(n)] for j in range(n)]

dp0[0]=0
dp[0]=0

dp0[1]=b[1][0]
dp[1]=dp0[1]

if k==1:
    for i in range(2,n):
        dp[i]=dp[i-1]+b[i][i-1]
    
if k > 1:
    for j in range(2,n):
        if j <=k:
            for i in range(j):
                dp0[j][i]=dp[i]+b[j][i]
            dp[j]=min(dp0[j])
        else:
            for i in range(k):
                dp0[j][i+j-k]=dp[i+j-k]+b[j][i+j-k]
            dp[j]=min(dp0[j])

#print(dp0)
print(dp[n-1])

Fixed submission:
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

print(dp[-1])

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

import numpy as np

a=np.array(h)
b=[[0 for i in range(n)] for j in range(n)]
b=np.array(b)

for j in range(n):
    for i in range(n):
        if j>i:
            b[j][i]=abs(a[j]-a[i])
#print(b)

dp=[int(0) for i in range(n)]
dp0=[[1000000000000000 for i in range(n)] for j in range(n)]

dp0[0]=0
dp[0]=0

dp0[1]=b[1][0]
dp[1]=dp0[1]

if k==1:
    for i in range(2,n):
        dp[i]=dp[i-1]+b[i][i-1]
    
if k > 1:
    for j in range(2,n):
        if j <=k:
            for i in range(j):
                dp0[j][i]=dp[i]+b[j][i]
            dp[j]=min(dp0[j])
        else:
            for i in range(k):
                dp0[j][i+j-k]=dp[i+j-k]+b[j][i+j-k]
            dp[j]=min(dp0[j])

#print(dp0)
print(dp[n-1])

Fixed submission:
n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
#print(n,k,h)
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])

if k > 1 and n > 2:
  for y in range(2,k):
    dp[y]=abs(h[y]-h[0])
    x=1
    while x < k:
      tmp=dp[x]+abs(h[y]-h[x])
      if tmp < dp[y]:
        dp[y]=tmp
      x+=1
  for y in range(k,n):    
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])
    for x in range(2,k+1):
      tmp=dp[y-x]+abs(h[y]-h[y-x])
      if tmp < dp[y]:
        dp[y]=tmp
        
if k == 1 and n > 2:
  for y in range(2,n):
    dp[y]=dp[y-1]+abs(h[y]-h[y-1])

print(dp[-1])