Buggy python submission (verdict: Time Limit Exceeded):
def test():
    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):
        dp[i] = min(dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,min(K,i)+1))
    
    print(dp[N-1])
    
if __name__ == '__main__':
    test()

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
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):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(i-K, 0), i))
    
print(dp[-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
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):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(i-K, 0), i))
    
print(dp[N-1])


Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
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):
  dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i)
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
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):
  dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i)
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
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):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i)
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
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):
    dp[i] = min(dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,min(K,i)+1))
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
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):
    dp[i] = min(dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,min(K,i)))
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
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):
    l = min(K,i)
    data = []
    dp[i] = min(dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,l+1))
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
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):
    l = min(K,i)
    data = []
    dp[i] = min(data, dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,l+1))
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
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):
    l = min(K,i)
    data = []
    dp[i] = min(data, dp[i-j]+abs(h[i] - h[i-j])) for j in range(1,l+1)
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq


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):
    l = min(K,i)
    data = []
    for j in range(1,l+1):
        heapq.heappush(data, dp[i-j]+abs(h[i] - h[i-j]))
    dp[i] = heapq.heappop(data)
    
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq


N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
i = 1


while not i==N:
    l = min(K,i)
    data = []
    for j in range(1,l+1):
        heapq.heappush(data, dp[i-j]+abs(h[i] - h[i-j]))
    dp[i] = heapq.heappop(data)
    i+=1
    
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq


N,K= [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
i = 1
dp = [0 for i in range(N)]

while not i==N:
    l = min(K,i)
    data = []
    for j in range(1,l+1):
        heapq.heappush(data, dp[i-j]+abs(h[i] - h[i-j]))
    dp[i] = heapq.heappop(data)
    i+=1
    
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
import heapq


N = int(input())
h = [int(i) for i in input().split()]
i = 1
dp = [0 for i in range(N)]
K = 2
 
while not i==N:
    l = min(K,i)
    data = []
    for j in range(1,l+1):
        heapq.heappush(data, dp[i-j]+abs(h[i] - h[i-j]))
    dp[i] = heapq.heappop(data)
    i+=1
    
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
i = 1
dp = [0 for i in range(N)]
 
while not i==N:
    l = min(K,i)
    data = [dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,l+1)]
    dp[i] = min(data)
    i+=1
    
print(dp[N-1])

Fixed submission:
def test():
    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):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()