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



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

main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[1] = abs(h[1] - h[0])

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

print(dp[-1])
                  



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

main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = (int(x) for x in input().split())
h = list(map(int,input().split()))
dp = [0]*n
dp[1] = abs(h[1] - h[0])

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

print(dp[-1])
                  



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

main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = (int(x) for x in input().split())
h = list(map(int,input().split()))
dp = [0]*n

# i = 1の時
dp[1] = abs(h[1] - h[0])

# i番目までの必要な体力を求める
for i in range(2,n):

    # i >= 2の時
    # i番目に必要な体力の最小値を求める
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-k),i))

print(dp[-1])
                  



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

main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k = (int(x) for x in input().split())
h = list(int(x) for x in input().split())
dp = [0]*n

# i = 1の時
dp[1] = abs(h[1] - h[0])

# i番目までの必要な体力を求める
for i in range(2,n):

    # i >= 2の時
    # i番目に必要な体力の最小値を求める
    dp[i] = (min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-k),i)))

print(dp[-1])
                  



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

main()

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

#i = 0の時
dp.append(0)

# i = 1の時
dp.append(abs(h[1] - h[0]))

# i番目までの必要な体力を求める
for i in range(2,n):

    # i >= 2の時
    # i番目に必要な体力の最小値を求める
    dp.append(min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-k),i)))

print(dp[-1])
                  



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

main()

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

#i = 0の時
dp.append(0)

# i = 1の時
dp.append(abs(h[1] - h[0]))

# i番目までの必要な体力を求める
for i in range(2,n):

    # i >= 2の時
    # i番目に必要な体力の最小値を求める
    hp = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-k),i))

    # 体力の追加
    dp.append(hp)

print(dp[-1])
                  



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

main()

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

# i番目までの必要な体力を求める
i = 0
while i != n:

    #i = 0の時
    if i == 0:
        dp.append(0)
        i += 1
        continue

    # i = 1の時
    if i == 1:
        dp.append(abs(h[i] - h[i-1]))
        i += 1
        continue

    # i >= 2の時
    hp = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-k),i))

    # 体力の追加
    dp.append(hp)

    i += 1

print(dp[-1])
                  



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

main()

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

# i番目までの必要な体力を求める
i = 0
while i != n:

    #i = 0の時
    if i == 0:
        dp.append(0)
        i += 1
        continue

    # i = 1の時
    if i == 1:
        dp.append(abs(h[i] - h[i-1]))
        i += 1
        continue

    # i >= 2の時
    # jの値の設定
    if i - k > 0:
        j = i - k
    else:
        j = 0

    # 初めの体力を代入
    hp = dp[j] + abs(h[i] - h[j])
    j += 1
    
    while j < i:
        
        hp1 = dp[j] + abs(h[i] - h[j])
        
        # 最小の体力を求める
        if hp > hp1:
            hp = hp1

        j += 1

    # 体力の追加
    dp.append(hp)

    i += 1

print(dp[-1])
                  



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

main()

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

# i番目までの必要な体力を求める
i = 0
while i != n:

    #i = 0の時
    if i == 0:
        dp.append(0)
        i += 1
        continue

    # i = 1の時
    if i == 1:
        dp.append(abs(h[i] - h[i-1]))
        i += 1
        continue

    # i >= 2の時
    # jの値の設定
    if i - k > 0:
        j = i - k
    else:
        j = 0

    hp = pow(10,18) 
    while j < i:
        
        hp1 = dp[j] + abs(h[i] - h[j])
        
        # 最小の体力を求める
        if hp > hp1:
            hp = hp1

        j += 1

    # 体力の追加
    dp.append(hp)

    i += 1

print(dp[-1])
                  



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

main()