Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")] * (n-1)
#print(dp)

for i in range(1,n):
    K = max(0, i - k) # K: 'i' ループ目の最大ジャンプ幅 'k' 
    H = h[i]          # H: 'i' ループ目の足場の高さ'h'
    for j in range(K, i):
        dp[i] = min(dp[i], dp[j]+abs(H - h[j]))
#print(dp)

print(dp[-1])



Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def frog_2():
    N, K = map(int,input().split())
    h = tuple(map(int,input().split()))

    dp = [float("inf")] * (N)
    dp[0] = 0

    for n in range(1, N):
        k = max(0, n - K)
        dp[n] = min(abs(h[n] - h[i]) + dp[i] for i in range(k, n))
        
    return print(dp[-1])

frog_2()

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int,input().split())
h = tuple(map(int,input().split()))

def frog_2(N, K ,h):
    dp = [float("inf")] * (N)
    dp[0] = 0

    for n in range(1, N):
        k = max(0, n - K)
        dp[n] = min(abs(h[n] - h[i]) + dp[i] for i in range(k, n))
        
    return dp[-1]

print(frog_2(N,K,h))

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int,input().split())
h = tuple(map(int,input().split()))

dp = [float("inf")] * (N)
dp[0] = 0

for n in range(1, N):
    k = max(0, n - K)
    dp[n] = min(abs(h[n] - h[i]) + dp[i] for i in range(k, n))

print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import numpy as np

n,k = map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.array([float("inf")]*(n))
dp[0] = 0
#print(dp)

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
#print(dp)
#    return print(dp[-1])

#frog_2(n,h,k)
print(int(dp[-1]))


Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
h = tuple(map(int,input().split()))

def frog_2(N, H, K):
    
    dp = [0] + [float("inf")]*(n-1)
    #print(dp)
    
    for i in range(1,n):
        for j in range(max(0,i-k),i):
            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
    #print(dp)
    return print(dp[-1])

frog_2(n,h,k)

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

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

dp = [0] + [float("inf")]*(n-1)
#print(dp)

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

print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
l = tuple(map(int, input().split()))
 
dp = [float('inf') for _ in range(n)]
dp[0] = 0

def frog_2(N, K):
    for i in range(n-1):
        for j in range(1, k+1):
            if i+j <= n-1:
                temp = dp[i] + abs(l[i+j] - l[i])
                if temp < dp[i+j]:
                    dp[i+j] = temp
     
    print(dp[-1])

frog_2(n, k)


Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
l = list(map(int, input().split()))
 
dp = [float('inf') for _ in range(n)]
dp[0] = 0

def frog_2(N, K):
    for i in range(n-1):
        for j in range(1, k+1):
            if i+j <= n-1:
                temp = dp[i] + abs(l[i+j] - l[i])
                if temp < dp[i+j]:
                    dp[i+j] = temp
     
    print(dp[-1])

frog_2(n, k)

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

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

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])