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

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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: Runtime Error):
def main():
    N,K=map(int,input().split())
    h=list(map(int,input().split()))
    ans=[0]*N
    ans[1]=ans(h[1]-h[0])
    for i in range(2,N):
        ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
    print(ans[-1])
main()

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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()))
ans=[0]*N
for i in range(1,N):
    ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
print(ans[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
print(ans[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    ans[i]=10**10
    ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
print(ans[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    ans[i]=10**10
    for j in range(max(0,i-K),i):
        ans[i]=min(abs(h[i]-h[j])+ans[j],ans[i])
print(ans[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    cost=[]
    for j in range(max(0,i-K),i):
        cost.append(abs(h[i]-h[j])+ans[j])
    ans[i]=min(cost)
print(ans[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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: Runtime Error):
N,K=map(int,input().split())
h=list(map(int,input().split()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    cost=[]
    for j in range(max(0,i-K),i):
        cost.append(abs(h[i]-h[c])+ans[c])
    ans[i]=min(cost)
print(ans[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,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()))
ans=[0]*N
ans[1]=abs(h[1]-h[0])
for i in range(2,N):
    cost=[]
    for j in range(1,K+1):
        if i>=j:
            c=i-j
            cost.append(abs(h[i]-h[c])+ans[c])
        else:
            break
    ans[i]=min(cost)
print(ans[-1])

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