Buggy python submission (verdict: Time Limit Exceeded):
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B - Frog 2
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10 ** 9] * N

    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        tmp = i - K
        if tmp < 0:
            tmp = 0
        for j in range(i - K, i):
            dp1 = dp[j] + abs(h[i] - h[j])
            if dp[i] >= dp1:
                dp[i] = dp1
                if dp[i] == 0:
                    break
            else:
                pass

    print(dp[N - 1])

main()

Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B - Frog 2
N, K = map(int,input().split())
h = list(map(int, input().split()))
dp = [10**9]*N

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,N):
    tmp = i-K
    if tmp < 0:
        tmp = 0
    for j in range(i-K,i):
        dp1 = dp[j]+ abs(h[i] - h[j])
        if dp[i] >= dp1:
            dp[i] = dp1
            if dp[i] == 0:
                break
        else:
            pass

print(dp[N-1])

Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B - Frog 2
N, K = map(int,input().split())
h = list(map(int, input().split()))
dp = [10**9]*N

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,N):
    for k in range(1,K+1):
        dp1 = dp[i - k]+ abs(h[i] - h[i - k])
        if dp[i] >= dp1:
            dp[i] = dp1
            if dp[i] == 0:
                break
        else:
            pass

print(dp[N-1])


Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B - Frog 2
N, K = map(int,input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,N):
    for k in range(1,K+1):
        dp1 = dp[i - k]+ abs(h[i] - h[i - k])
        if dp[i] >= dp1:
            dp[i] = dp1
            if dp[i] == 0:
                break
        else:
            pass

print(dp[N-1])

Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B - Frog 2
N, K = map(int,input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,N):
    for k in range(1,K+1):
        dp1 = dp[i - k]+ abs(h[i] - h[i - k])
        if dp[i] >= dp1:
            dp[i] = dp1
        else:
            pass
print(dp[N-1])

Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B - Frog 2
N, K = map(int,input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N

dp[0] = 0
for i in range(1,N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        for k in range(1,K+1):
            dp1 = dp[i - k]+ abs(h[i] - h[i - k])
            if dp[i] >= dp1:
                dp[i] = dp1
            else:
                pass

print(dp[N-1])

Fixed submission:
#B - Frog 2
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

#print(dp)
print(dp[N-1])