Buggy python submission (verdict: Runtime Error):
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf * number]
res[0] =0 
test = [math.inf * number]
test[0] = 0

for i in range(number):
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        test[j-1] = res[i-j] + cost
    
    res[i] = min(test)
    

print(res[number-1])




Fixed submission:
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf for i in range(number)]
res[0] =0 
test = [math.inf for k in range(jump)]
test[0] = 0

for i in range(number):
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        test[j-1] = res[i-j] + cost
    
    res[i] = min(test)
    

print(res[number-1])




Fixed submission:
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf for i in range(number)]
res[0] =0 
test = [math.inf for k in range(jump)]
test[0] = 0

for i in range(number):
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        test[j-1] = res[i-j] + cost
    
    res[i] = min(test)
    

print(res[number-1])




Fixed submission:
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf for i in range(number)]
res[0] =0 


for i in range(number):
    test = [math.inf for k in range(jump)]
    test[0] = 0
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        test[j-1] = res[i-j] + cost
    
    res[i] = min(test)
    

print(res[number-1])

Fixed submission:
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf for i in range(number)]
res[0] =0 
for i in range(number):
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        res[i]=min(res[i],res[i-j]+cost)

print(res[number-1])


Fixed submission:
import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])