ZhenlongDai/ACPR huggingface dataset:
Problem: p03170
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
  n,k=map(int,input().split())
  num=[int(i) for i in input().split()]
  
  dp=[0]*(k+1)
  for i in range(k):
    flag=False
    for j in range(n):
      if dp[max(i+1-num[j],0)]==0:
        flag=True
        break
    if flag:
      dp[i+1]=1
    else:
      continue
  if dp[k]:
    print('First')
  else:
    print('Second')          
if __name__=='__main__':
  main()

Failing test case input:
2 4
2 5

Expected output:
Second


Actual output:
First


Fixed submission (verdict: Accepted):
def main():
  n,k=map(int,input().split())
  num=[int(i) for i in input().split()]
  
  dp=[0]*(k+1)
  for i in range(k):
    flag=False
    for j in range(n):
      if i+1-num[j]>=0:
        if  dp[i+1-num[j]]==0:
          flag=True
          break
    if flag:
      dp[i+1]=1
    else:
      continue
  if dp[k]:
    print('First')
  else:
    print('Second')          
if __name__=='__main__':
  main()

Problem: p03170
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [0] * (K+1)

for i in range(0,K+1):
    if dp[i] == 0:
        for j in A:
            if i + j > K:
                break
            dp[i + j] = 1

print('first' if dp[K] else 'second')

Failing test case input:
1 100000
2

Expected output:
Second


Actual output:
second


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [0] * (K+1)

for i in range(0,K+1):
    if dp[i] == 0:
        for j in A:
            if i + j > K:
                break
            dp[i + j] = 1

print('First' if dp[K] else 'Second')

Problem: p03170
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [0 for i in range(k+1)]
for i in range(len(dp)):
    for j in arr:
        if j+i < k+1:
            dp[j+i] = (dp[i]+1)%2

ans = "First" if dp[-1] else "Second"
print(ans)



Failing test case input:
2 13
2 3

Expected output:
First


Actual output:
Second


Fixed submission (verdict: Accepted):
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [0 for i in range(k+1)]

for i in range(len(dp)):
    if dp[i] == 0:
        for j in arr:
            if j+i < k+1:
                dp[j+i] = 1

ans = "First" if dp[-1] else "Second"
print(ans)
Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

def solver():
	N,K = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [0 for _ in range(N)]
	for i in range(1,N):
		min_cost = 100000
		for j in range(max(0, i-K),i):
			cost = dp[j] + abs(h[i]-h[j])
			if cost < min_cost : min_cost = cost
		dp[i] = min_cost
	print(dp)
	print(dp[N-1])

solver()

Failing test case input:
4 4
75 10 17 70 22 10 20 70 121 126

Expected output:
5


Actual output:
[0, 65, 58, 5]
5


Fixed submission (verdict: Accepted):
def solver():
	N,K = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [0 for _ in range(N)]
	for i in range(1,N):
		min_cost = 10**10
		for j in range(max(0, i-K),i):
			cost = dp[j] + abs(h[i]-h[j])
			if cost < min_cost : min_cost = cost
		dp[i] = min_cost
	print(dp[N-1])

solver()

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k = map(int,input().split())
arr = [int(i) for i in input().split()]
dp = [float("inf") for j in range(n)]
dp[0] = 0
for i in range(n):
    dp[i] = float("inf")
    for j in range(i+1,i+k+1):
        if j < n:
            val = (abs(arr[i]-arr[j]) + dp[i]) 
            dp[j] = min(dp[j],val)
print(dp[n-1])


Failing test case input:
6 1
40 10 34 219 155 10 20 11 80 118

Expected output:
448


Actual output:
inf


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
arr = [int(i) for i in input().split()]
dp = [float("inf")] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j < n:
            dp[j] = min(dp[j],abs(arr[i]-arr[j]) + dp[i])
print(dp[n-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for i in range(N)]
for i in range(N):
    for j in range(1,K+1):
        if i+j<N:
            if dp[i+j] == 0:
                dp[i+j] = dp[i]+abs(h[i]-h[j])
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        
print(dp[-1])

Failing test case input:
5 1
76 10 19 219 155 10 20 11 80 60

Expected output:
339


Actual output:
139


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**15+1 for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j<N:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        
print(dp[-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


Failing test case input:
5 1
40 19 34 398 254 10 13 13 20 118

Expected output:
544


Actual output:
502


Fixed submission (verdict: Accepted):
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans

print(dp[n-1])
Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
x,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*x
dp[1]=abs(a[1]-a[0])
for i in range(2,x):
    p=1000001
    
    for j in range(max(0,i-k),i):
        
        p=min(p,dp[j]+abs(a[i]-a[j]))
        
    dp[i]=p
print(dp[x-1],dp)    

Failing test case input:
6 1
40 19 34 219 155 10 13 11 80 118

Expected output:
430


Actual output:
430 [0, 21, 36, 221, 285, 430]


Fixed submission (verdict: Accepted):
x,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*x
dp[1]=abs(a[1]-a[0])
for i in range(2,x):
    p=10000000001
    for j in range(max(0,i-k),i):
        p=min(p,dp[j]+abs(a[i]-a[j]))
        
    dp[i]=p
print(dp[x-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = list(map(int, input().split()))

a = [0]*n

for i in range(1, n):
  b = a[max(0, i-k)] + abs(h[i]-h[max(0, i-k)])
  for j in range(max(0, i-k), i-1):
    b = min(b, a[j] + abs(h[i]-h[j]))
  a[i] = b
print(a[-1])

Failing test case input:
10 3
40 9 20 70 80 10 17 70 135 60

Expected output:
60


Actual output:
100


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
hs = list(map(int, input().split()))
 
dp = [0]*n
 
for i in range(1, n):
  first = max(0, i-k)
  dp[i] = min([d + abs(hs[i]-h) for d, h in zip(dp[first:i], hs[first:i])])
print(dp[-1])

Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N,K=map(int,input().split())
h_list=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=float("inf")
    for j in range(1,min(i,K+1)+1):
        dp[i]=min(dp[i],dp[i-j]+abs(h_list[i-j]-h_list[i]))
print(dp[-1])

Failing test case input:
3 1
0 20 10

Expected output:
30


Actual output:
10


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
h_list=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=float("inf")
    for j in range(1,min(i,K)+1):
        dp[i]=min(dp[i],dp[i-j]+abs(h_list[i-j]-h_list[i]))
print(dp[-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j >= n:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp)
print(dp[n - 1])

Failing test case input:
5 6
25 10 1 0 9 21 9 91 121 60

Expected output:
16


Actual output:
[0, 15, 24, 25, 16]
16


Fixed submission (verdict: Accepted):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])
Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
(N,K) = map(int,input().split())
h = list(map(int,input().split()))
n = 2
cost = [0]*N
cost[1] = abs(h[1]-h[0])
for n in range(2,N):
    costmin = 10**10
    for i in range(max(0,n-K),min(n,K)):
        costmin = min(costmin,cost[i]+abs(h[n]-h[i]))
    cost[n] = costmin
    
print(cost)

Failing test case input:
9 6
28 10 1 0 9 21 9 179 223 119

Expected output:
209


Actual output:
[0, 18, 27, 28, 19, 7, 19, 165, 209]


Fixed submission (verdict: Accepted):
(N,K) = map(int,input().split())
h = list(map(int,input().split()))
n = 2
cost = [0]*N
cost[1] = abs(h[1]-h[0])
for n in range(2,N):
    costmin = 10**10
    for i in range(max(0,n-K),n):
        costmin = min(costmin,cost[i]+abs(h[n]-h[i]))
    cost[n] = costmin
    
print(cost[N-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int,input().split())
H = list(map(int,input().split()))

dp = [0]*N
dp[1]= abs(H[1]-H[0])

inf = float("inf")

for i in range(1,N-1):
    tmp = inf
    oppai = min(K,i+1)
    for jump in range(1,oppai+1):
        tmp = min(tmp,dp[i+1-jump]+abs(H[i+1]-H[i+1-jump]))
    dp[i+1]=tmp
print(dp)
  


Failing test case input:
6 1
40 19 34 219 155 10 13 11 80 118

Expected output:
430


Actual output:
[0, 21, 36, 221, 285, 430]


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
H = list(map(int,input().split()))

dp = [0]*N
dp[1]= abs(H[1]-H[0])

inf = float("inf")

for i in range(1,N-1):
    tmp = inf
    oppai = min(K,i+1)
    for jump in range(1,oppai+1):
        tmp = min(tmp,dp[i+1-jump]+abs(H[i+1]-H[i+1-jump]))
    dp[i+1]=tmp
print(dp[N-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**8+1 for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j<N:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        
print(dp)

Failing test case input:
3 1
10 31 10

Expected output:
42


Actual output:
[0, 21, 42]


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**15+1 for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j<N:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        
print(dp[-1])
Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if dp[i] + temp < dp[i+j]:
                dp[i+j] = temp

print(dp[n-1])

Failing test case input:
10 3
40 9 20 70 80 10 17 70 135 60

Expected output:
60


Actual output:
80


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

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

Failing test case input:
5 1
3 26 59 149 208 10 13 20 39 84

Expected output:
205


Actual output:
59


Fixed submission (verdict: Accepted):
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int,input().split())
h = list(map(int,input().split()))

dp = [0] * N
dp[1] = abs(h[0] - h[1])

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

print(dp)

Failing test case input:
9 6
28 10 1 0 9 22 6 179 433 119

Expected output:
417


Actual output:
[0, 18, 27, 28, 19, 6, 22, 163, 417]


Fixed submission (verdict: Accepted):
def main():
    N, K = map(int,input().split())
    h = list(map(int,input().split()))
    
    dp = [0] * N
    dp[1] = abs(h[0] - h[1])
    
    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])

if __name__ == '__main__':
    main()

Problem: p03161
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]
for i in range(1,n):    
    mi=[]
    for j in range(1,k+1):
        if i-j>=0 :
            mi.append(dp[i-j]+abs(l[i]-l[i-j]))
            dp.append(min(mi))

print(dp[-1])

Failing test case input:
10 4
40 9 20 70 80 10 20 70 80 105

Expected output:
65


Actual output:
55


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):    
    start=max(0,i-k)
    dp[i]=min(dp[j]+abs(l[i]-l[j]) for j in range(start,i))
print(dp[-1])
Problem: p03161
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k= map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**7
dp = [inf]*100005
dp[0] = 0
for i in range(1,n):
    con = inf
    for j in range(1,k):
        if j > len(h):
            break
        con = min(con,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = con
print(dp[n-1])

Failing test case input:
10 4
40 9 33 70 80 10 20 70 84 31

Expected output:
31


Actual output:
51


Fixed submission (verdict: Accepted):
def main():
    n,k= map(int,input().split())
    h = [int(i) for i in input().split()]
    inf = 10**7
    dp = [inf]*100005
    dp[0] = 0
    for i in range(1,n):
        dp[i] = min(dp[i-j] + abs(h[i-j] - h[i]) for j in range(1,min(k,i)+1))
    print(dp[n-1])
main()

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [100000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
    print(dp)
print(dp[n-1])

Failing test case input:
5 1
40 31 59 219 208 10 13 13 39 118

Expected output:
208


Actual output:
[0, 9, 100000, 100000, 100000]
[0, 9, 37, 100000, 100000]
[0, 9, 37, 197, 100000]
[0, 9, 37, 197, 208]
[0, 9, 37, 197, 208]
208


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [1000000000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
print(dp[n-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k,*h=map(int,open(0).read().split())
dp=[10**18]*(n+k+1)
h=h+[0]*k
dp[0]=0
for i in range(n):
  for j in range(k):
    dp[j+i+1]=min(dp[i],dp[i+j+1]+abs(h[i+j+1]-h[i]))
print(dp[n-1])

Failing test case input:
5 6
25 10 14 70 0 21 9 91 121 60

Expected output:
25


Actual output:
0


Fixed submission (verdict: Accepted):
n,k,*h=map(int,open(0).read().split())
dp=[10**18]*(n+k+1)
h=h+[0]*k
dp[0]=0
for i in range(n):
  for j in range(k):
    dp[j+i+1]=min(dp[i+j+1],dp[i]+abs(h[i+j+1]-h[i]))
print(dp[n-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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 j in range(1, K+1):
        if i >= j:
            dp[i] = min(dp[i], dp[i-j] + abs(H[i-j] - H[i]))
print(dp)

print(dp[N-1])



Failing test case input:
2 100
17 9

Expected output:
8


Actual output:
[0, 8]
8


Fixed submission (verdict: Accepted):
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 j in range(1, K+1):
        if i >= j:
            dp[i] = min(dp[i], dp[i-j] + abs(H[i-j] - H[i]))

print(dp[N-1])
Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
INF = 1e9
n,k = map(int, input().split())
h = list(map(int, input().split()))
ans = [INF]*n
ans[1] = abs(h[1]-h[0])
for i in range(2,n):
    x = max(0, i-k)
    for j in range(x,i):
        ans[i]=min(ans[i], abs(h[i]-h[j])+ans[j])
print(ans[-1])

Failing test case input:
9 6
44 10 1 0 9 21 9 179 223 119

Expected output:
225


Actual output:
247


Fixed submission (verdict: Accepted):
INF = 1e9
n,k = map(int, input().split())
h = list(map(int, input().split()))
ans = [INF]*n
ans[0]= 0
ans[1] = abs(h[1]-h[0])
for i in range(2,n):
    x = max(0, i-k)
    for j in range(x,i):
        ans[i]=min(ans[i], abs(h[i]-h[j])+ans[j])
print(ans[-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solver():
	N,K = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [0 for _ in range(N)]
	for i in range(1,N):
		min_cost = 100000000000000
		for j in range(max(0, i-K),i):
			cost = dp[j] + abs(h[i]-h[j])
			if cost < min_cost : min_cost = cost
		dp[i] = min_cost
	print(dp)
	print(dp[N-1])

solver()

Failing test case input:
5 1
27 14 165 86 208 10 13 20 61 134

Expected output:
365


Actual output:
[0, 13, 164, 243, 365]
365


Fixed submission (verdict: Accepted):
def solver():
	N,K = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [0 for _ in range(N)]
	for i in range(1,N):
		min_cost = 10**10
		for j in range(max(0, i-K),i):
			cost = dp[j] + abs(h[i]-h[j])
			if cost < min_cost : min_cost = cost
		dp[i] = min_cost
	print(dp[N-1])

solver()

Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
(N,K) = map(int,input().split())
h = list(map(int,input().split()))
n = 2
cost = [0]*N
cost[1] = abs(h[1]-h[0])
for n in range(2,N):
    costmin = 10**10
    for i in range(max(0,n-K),min(n,K)):
        costmin = min(costmin,cost[i]+abs(h[n]-h[i]))
    cost[n] = costmin
    
print(cost[N-1])

Failing test case input:
3 1
10 31 10

Expected output:
42


Actual output:
10000000000


Fixed submission (verdict: Accepted):
(N,K) = map(int,input().split())
h = list(map(int,input().split()))
n = 2
cost = [0]*N
cost[1] = abs(h[1]-h[0])
for n in range(2,N):
    costmin = 10**10
    for i in range(max(0,n-K),n):
        costmin = min(costmin,cost[i]+abs(h[n]-h[i]))
    cost[n] = costmin
    
print(cost[N-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [INF] * (N+K)
dp[0] = 0

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

Failing test case input:
3 1
1 20 10

Expected output:
29


Actual output:
[0, 19, 29, 39] [1, 20, 10, 0]


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [INF] * (N+K)
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))
print(dp[N-1])
Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from math import inf

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [inf for i in range(n)]
dp[0] = 0

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

print(dp)


Failing test case input:
3 1
40 10 14 70 80 10 15 91 121 60

Expected output:
34


Actual output:
[0, 30, 34]


Fixed submission (verdict: Accepted):
from math import inf

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [inf for i in range(n)]
dp[0] = 0

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

print(dp[-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,N):
  for j in range(1,i):
      dpx = min(dpx, abs(h[i]-h[i-j])+dp[i-j])
  dp.append(dpx)
print(dp[-1])

Failing test case input:
7 1
26 19 34 219 155 10 13 11 20 118

Expected output:
419


Actual output:
10001


Fixed submission (verdict: Accepted):
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()

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


def func():
    N, k = map(int, input().split() )
    h = list( map(int,input().split()) )

    dp = [0] * N
    for n in range(1, N):
        
        
        
        
        
        
        dp[n] = min([ dp[max(n-k, 0)] + abs(h[n]-h[max(n-k,0)]) for k in range(max(n-k,0), n) ])
    print(dp[N-1])

if __name__=='__main__':
    func()





Failing test case input:
3 1
1 19 10

Expected output:
27


Actual output:
9


Fixed submission (verdict: Accepted):


def func():
    N, k = map(int, input().split() )
    h = list( map(int,input().split()) )

    dp = [float('inf')] * N
    dp[0] = 0
    for n in range(1, N):
        
        
        
        
        
        
        dp[n] = min([ dp[j] + abs(h[n]-h[j]) for j in range(max(n-k,0), n) ])
    print(dp[N-1])

if __name__=='__main__':
    func()

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[float("inf")]*n
cost[0]=0
cost[1]=abs(h[1]-h[0])

for i in range(1,n-1):
    for j in range(1,k+1):
        if i+j>n-1:
            continue
        else:
            cost[i+j]=min(abs(h[i+j]-h[i])+cost[i] ,cost[i+j])

print(cost[n-1])


Failing test case input:
3 4
40 10 34 70 80 10 20 70 80 60

Expected output:
6


Actual output:
54


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[float("inf")]*n
cost[0]=0

for i in range(n):
    for j in range(1,k+1):
        if i+j>n-1:
            continue
        else:
            cost[i+j]=min(abs(h[i+j]-h[i])+cost[i] ,cost[i+j])

print(cost[n-1])
Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N,K=map(int,input().split())
h=list(map(int,input().split()))

dp=[0 for i in range(N)]
dp[1]=abs(h[1]-h[0])


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

print(dp[N-1])
    
    

Failing test case input:
3 4
21 10 17 70 73 10 20 70 80 60

Expected output:
4


Actual output:
18


Fixed submission (verdict: Accepted):
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] = min(abs(h[i] - h[j]) + ans[j] for j in range(max(0,i-K),i))
    print(ans[N-1])
    
main()

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



n,k = map(int,input().split())
h = [0] + list(map(int,input().split()))


dp = [0 for i in range(n+1)]
dp[2] = abs(h[2]-h[1])

for i in range(3,n+1):
    arr = [dp[i-j] + abs(h[i] - h[i-j]) for j in range(1,min(i,k)+1)]
    dp[i] = min(arr)


ans = dp[n]
print(ans)


Failing test case input:
9 6
44 10 1 0 9 21 9 179 223 119

Expected output:
225


Actual output:
223


Fixed submission (verdict: Accepted):



n,k = map(int,input().split())
h = [0] + list(map(int,input().split()))


dp = [0 for i in range(n+1)]
dp[2] = abs(h[2]-h[1])

for i in range(3,n+1):
    arr = [dp[i-j] + abs(h[i] - h[i-j]) for j in range(1,min(i-1,k)+1)]
    dp[i] = min(arr)


ans = dp[n]
print(ans)

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





N,K=map(int,input().split())
h=[int(num) for num in input().split()]

dp=[0]*N
dp[1]=abs(h[0]-h[1])
   
def cost(h,N,K,dp):
    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)])
    return dp[-1]
    
print(h,N,K,dp)

Failing test case input:
3 1
40 10 14 70 80 10 15 91 121 60

Expected output:
34


Actual output:
[40, 10, 14, 70, 80, 10, 15, 91, 121, 60] 3 1 [0, 30, 0]


Fixed submission (verdict: Accepted):





N,K=map(int,input().split())
h=[int(num) for num in input().split()]

dp=[0]*N
dp[1]=abs(h[0]-h[1])
   
def cost(h,N,K,dp):
    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)])
    return dp[-1]
    
print(cost(h,N,K,dp))

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
DP = [float("inf")]*N

for i in range(1,min(K,N)):
    DP[i] = abs(h[i]-h[0])

DP[1] = abs(h[1]-h[0])
for i in range(K,N):
    for k in range(1,K+1):
        DP[i] = min(DP[i],DP[i-k]+abs(h[i]-h[i-k]))
print(DP[N-1])

Failing test case input:
5 2
46 10 34 219 155 12 20 15 80 60

Expected output:
133


Actual output:
181


Fixed submission (verdict: Accepted):
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
DP = [float("inf")]*N

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

DP[1] = abs(h[1]-h[0])
for i in range(K+1,N):
    for k in range(1,K+1):
        DP[i] = min(DP[i],DP[i-k]+abs(h[i]-h[i-k]))
print(DP[N-1])
Problem: p03161
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K = map(int,input().split())
h = list(map(int,input().split()))

cost = [0]
for i in range(2,N+1):
    print(i)
    cost.append( min([cost[j] + abs(h[i-1]-h[j]) for j in range(max(0,i-K-1), i-1)]) )
print(cost)

Failing test case input:
9 6
28 10 1 0 9 22 6 179 433 119

Expected output:
417


Actual output:
2
3
4
5
6
7
8
9
[0, 18, 27, 28, 19, 6, 22, 163, 417]


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = list(map(int,input().split()))

cost = [0]
for i in range(2,N+1):
    cost.append( min([cost[j] + abs(h[i-1]-h[j]) for j in range(max(0,i-K-1), i-1)]) )
print(cost[-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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]=abs(h[i]-h[i-1])+dp[i-1]
    for j in range(i-2,max(0,i-K)-1,-1):
        dp2=abs(h[i]-h[j])+dp[j]
        if dp[i]>dp2:
            dp[i]=dp2
print(dp)
print(dp[N-1])

Failing test case input:
5 1
27 14 99 86 208 10 13 20 61 134

Expected output:
233


Actual output:
[0, 13, 98, 111, 233]
233


Fixed submission (verdict: Accepted):
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]=abs(h[i]-h[i-1])+dp[i-1]
    for j in range(i-2,max(0,i-K)-1,-1):
        dp2=abs(h[i]-h[j])+dp[j]
        if dp[i]>dp2:
            dp[i]=dp2
print(dp[N-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 1001001001
dp = [inf] * (n+1)

dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(n):
    for j in range(k):
        if i + j >= n:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[n-1])


Failing test case input:
3 1
4 8 1

Expected output:
11


Actual output:
1001001001


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 1001001001
dp = [inf] * (n+1)

dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(n):
    for j in range(k):
        if i + j >= n:
            break
        dp[i + j] = min(dp[i + j], dp[i-1] + abs(h[i+j] - h[i-1]))
print(dp[n-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list(map(int, input().split()))

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

Failing test case input:
10 4
40 9 20 70 80 10 20 70 80 60

Expected output:
40


Actual output:
20


Fixed submission (verdict: Accepted):
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))
Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]

cost=[0]
for i in range(1,N):
    m_cost=999999
    for j in range(1,min(K,i)+1):
        if m_cost>=cost[i-j]+abs(h[i]-h[i-j]):
            m_cost=cost[i-j]+abs(h[i]-h[i-j])
    cost.append(m_cost)
print(cost.pop()) 

print(cost)





Failing test case input:
3 1
40 10 17 70 80 10 9 91 121 60

Expected output:
37


Actual output:
37
[0, 30]


Fixed submission (verdict: Accepted):
N, K=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]

cost=[0]
for i in range(1,N):
    m_cost=99999999999
    for j in range(1,min(K,i)+1):
        if m_cost>=cost[i-j]+abs(h[i]-h[i-j]):
            m_cost=cost[i-j]+abs(h[i]-h[i-j])
    cost.append(m_cost)
print(cost.pop())

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k = map(int,input().split())
h = list(map(int,input().split()))

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

print(dp[n-1])

Failing test case input:
5 5
41 10 14 73 80 21 9 91 121 60

Expected output:
39


Actual output:
101


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = list(map(int,input().split()))

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

print(dp[n-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



n,k = map(int,input().split())
h = [0] + list(map(int,input().split()))


dp = [0 for i in range(n+1)]
dp[2] = abs(h[2]-h[1])

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


ans = dp[n]
print(ans)


Failing test case input:
6 4
25 10 17 70 80 12 9 91 121 60

Expected output:
13


Actual output:
12


Fixed submission (verdict: Accepted):



n,k = map(int,input().split())
h = [0] + list(map(int,input().split()))


dp = [0 for i in range(n+1)]
dp[2] = abs(h[2]-h[1])

for i in range(3,n+1):
    arr = [dp[i-j] + abs(h[i] - h[i-j]) for j in range(1,min(i-1,k)+1)]
    dp[i] = min(arr)


ans = dp[n]
print(ans)

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*N

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

Failing test case input:
5 1
40 10 34 219 155 10 20 11 80 60

Expected output:
303


Actual output:
100


Fixed submission (verdict: Accepted):
n,k=map(int, input().split())
h=list(map(int, input().split()))+[0]*2*k
dp=[10**10]*(n*10)+[10**10]*2*k
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(n):
    for j in range(1,k+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])
Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int, input().split())
H = list(map(int, input().split()))

table = [0]*N

for i in range(1, N):
    if i < K:
        table[i] = min([table[i1] + abs(H[i1]-H[i]) for i1 in range(0, i)])
        print(table)
    else:
        table[i] = min(
            [table[i-k] + abs(H[i-k]-H[i]) for k in range(1, K+1)]
        )


print(table[-1])

Failing test case input:
3 4
40 10 17 70 80 10 20 70 80 60

Expected output:
23


Actual output:
[0, 30, 0]
[0, 30, 23]
23


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
H = list(map(int, input().split()))

table = [0]*N

for i in range(1, N):
    if i < K:
        table[i] = min(
            [table[i1] + abs(H[i1]-H[i]) for i1 in range(0, i)])

    else:
        table[i] = min(
            [table[i-k] + abs(H[i-k]-H[i]) for k in range(1, K+1)]
        )


print(table[-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = abs(h[0] - h[-1])
dp = [inf] * n
dp[0] = 0
for i in range(n):
    dp[i] = min([dp[i - j]  + abs(h[i - j] - h[i]) for j in range(min(k+1, i+1))])
print(dp[-1])


Failing test case input:
10 1
65 19 34 219 208 10 13 13 39 118

Expected output:
563


Actual output:
53


Fixed submission (verdict: Accepted):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [0]*(n)
dp[0] = 0
for i in range(n):
  for j in range(i+1,k+i+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])

 

Failing test case input:
5 1
40 29 59 219 208 10 13 13 39 84

Expected output:
212


Actual output:
0


Fixed submission (verdict: Accepted):
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [sys.maxsize]*(n)
dp[0] = 0
for i in range(n):
  for j in range(i+1,k+i+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def input():
    return sys.stdin.readline().strip()


n,k=map(int,input().split())
cst=list(map(int,input().split()))
arr=[0]*n
arr[1]=abs(cst[1]-cst[0])
for i in range(2, n):
    arr[i]=min(abs(cst[j]-cst[i])+arr[j] for j in  range(max(i-k,0),i))
    print(arr[n-1])



Failing test case input:
5 1
7 19 34 219 208 10 13 11 20 118

Expected output:
223


Actual output:
0
0
223


Fixed submission (verdict: Accepted):
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    n, k = map(int, input().split())
    cst = list(map(int, input().split()))
    arr = [0] * n
    arr[1] = abs(cst[1] - cst[0])
    for i in range(2, n):
        arr[i] = min(abs(cst[j] - cst[i]) + arr[j] for j in range(max(i - k, 0), i))
    print(arr[n - 1])
if __name__ == '__main__':
    main()
Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k = map(int,input().split())
a = list(map(int,input().split()))
cost = [0] * n
cost[1] = abs(a[1]-a[0])
mi = 999999
for i in range(1,n):
    for j in range(max(0,i-k-1),i):
        mi = min(mi,cost[j]+abs(a[i]-a[j]))
        
    
    cost[i] = mi
    mi = 999999

print(cost[n-1])

Failing test case input:
3 1
0 38 10

Expected output:
66


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))
cost = [0] * n
cost[1] = abs(a[1]-a[0])
mi = sys.maxsize
for i in range(1,n):
    for j in range(max(0,i-k),i):
        mi = min(mi,cost[j]+abs(a[i]-a[j]))
        
    
    cost[i] = mi
    mi = sys.maxsize

print(cost[n-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
h=list(map(int,input().split()))
min_cost=[0]*n
min_cost[0]=h[0]
min_cost[1]=abs(h[1]-h[0])
for i in range(2,n):
    s=[]
    for j in range(1,k+1):
        s.append(min_cost[i-j]+abs(h[i]-h[i-j]))
    min_cost[i]=min(s)
print(min_cost[-1])

Failing test case input:
4 4
75 10 17 70 22 10 20 70 121 126

Expected output:
5


Actual output:
56


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=list(map(int,input().split()))
min_cost=[0]*n
min_cost[0]=0
min_cost[1]=abs(h[1]-h[0])
for i in range(2,n):
    s=[]
    for j in range(1,k+1):
        if i-j<0:
            continue
        s.append(min_cost[i-j]+abs(h[i]-h[i-j]))
    min_cost[i]=min(s)
print(min_cost[-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
h = list(map(int, input().split()))

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

print(dp)

Failing test case input:
2 100
7 10

Expected output:
3


Actual output:
[0, 3]


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = list(map(int, input().split()))

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

print(dp[n-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [sum(H) + 1] * (N + 1)
dp[0] = 0
H += [sum(H) + 1]

for i in range(N):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i+k], dp[i] + abs(H[i+k] - H[i]))

print(dp[N-1])

Failing test case input:
5 1
10 30 7 50 2

Expected output:
134


Actual output:
100


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))

dp = [10 ** 10] * (N+1)
dp[1] = 0

for i in range(1, N+1):
    for j in range(1, K+1):
        if i + j > N:
            continue
        dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j] - H[i]))

print(dp[N])
Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [0 for i in range(N)]
dp[1] = dp[0] + abs(h[1] - h[0])

for i in range(2, N):
    nums = list(range(i-K, i))
    li = [dp[num] + abs(h[i] - h[num]) for num in nums]
    dp[i] = min(li)

    
print(dp[N-1])

Failing test case input:
7 4
40 9 20 70 80 9 43 70 135 60

Expected output:
43


Actual output:
37


Fixed submission (verdict: Accepted):
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [0 for i in range(N)]
dp[1] = dp[0] + abs(h[1] - h[0])

for i in range(2, N):
    if (i-K < 0) :
        nums = list(range(i))
    else :
        nums = list(range(i-K, i))
    li = [dp[num] + abs(h[i] - h[num]) for num in nums]
    dp[i] = min(li)

print(dp[N-1])

Problem: p03161
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(1, n):
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(h[i]-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


Failing test case input:
9 6
28 10 1 0 9 22 9 179 223 119

Expected output:
207


Actual output:
231


Fixed submission (verdict: Accepted):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9]*n

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

Failing test case input:
5 3
10 40 64 46 24

Expected output:
46


Actual output:
1000000000


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9]*n

dp[0]=0
for i in range(1,n):
    for j in range(1,min(k+1,i+1)):
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
    
print(dp[n-1])
Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, k = map(int,input().split())
hl = list(map(int,input().split()))

dp = [[] for _ in range(n)]
dp[0] = 0

for i in range(1,n):
    tmp = float('inf')
    for j in range(1,k+1):
        if i-j < 0:
            continue
        tmp = min(dp[i-j] + abs(hl[i]-hl[i-j]),tmp)
    dp[i] = tmp
print(dp)

Failing test case input:
6 1
40 19 34 219 155 10 13 11 80 118

Expected output:
430


Actual output:
[0, 21, 36, 221, 285, 430]


Fixed submission (verdict: Accepted):
n, k = map(int,input().split())
hl = list(map(int,input().split()))

dp = [[] for _ in range(n)]
dp[0] = 0

for i in range(1,n):
    tmp = float('inf')
    for j in range(1,k+1):
        if i-j < 0:
            continue
        tmp = min(dp[i-j] + abs(hl[i]-hl[i-j]),tmp)
    dp[i] = tmp
print(dp[-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [0] * n

for i in range(n):
  dp_temp = 10**5
  for j in range(1, k+1):
    if i-j >= 0:
      temp = dp[i-j] + abs(h[i]-h[i-j])
      if dp_temp >= temp:
        dp_temp = temp
    else:
      break
  dp[i] = dp_temp
print(dp[n-1])
  

Failing test case input:
2 100
10 9

Expected output:
1


Actual output:
100000


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [0] * n

for i in range(n):
  dp_temp = 0
  flag = 0
  for j in range(1, k+1):
    if i-j >= 0:
      temp = dp[i-j] + abs(h[i]-h[i-j])
      if flag == 0:
        dp_temp = temp
        flag = 1
      else:
        if dp_temp >= temp:
          dp_temp = temp
    else:
      break
  dp[i] = dp_temp
print(dp[n-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


def func():
    N, k = map(int, input().split() )
    h = list( map(int,input().split()) )

    dp = [float('inf')] * N
    dp[0] = 0
    for n in range(1, N):
        print(n)
        
        
        
        
        
        
        dp[n] = min([ dp[j] + abs(h[n]-h[j]) for j in range(max(n-k,0), n) ])
    print(dp[N-1])

if __name__=='__main__':
    func()





Failing test case input:
6 1
40 19 34 219 155 10 13 11 80 118

Expected output:
430


Actual output:
1
2
3
4
5
430


Fixed submission (verdict: Accepted):


def func():
    N, k = map(int, input().split() )
    h = list( map(int,input().split()) )

    dp = [float('inf')] * N
    dp[0] = 0
    for n in range(1, N):
        
        
        
        
        
        
        dp[n] = min([ dp[j] + abs(h[n]-h[j]) for j in range(max(n-k,0), n) ])
    print(dp[N-1])

if __name__=='__main__':
    func()
Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k = map(int, input().split())
H = [0]+list(map(int, input().split()))
dp = [float("inf")]*(n+1)
dp[0] = 0
dp[1] = 0

for i in range(n):
  for k_i in range(1, k+1):
    if i+k_i<=n:
      dp[i+k_i] = min(dp[i+k_i], dp[i]+abs(H[i+k_i]-H[i]))
      
print(dp[-1])

Failing test case input:
5 6
25 10 1 0 9 21 9 91 121 60

Expected output:
16


Actual output:
9


Fixed submission (verdict: Accepted):
n,k = map(int, input().split())
H = [0]+list(map(int, input().split()))
dp = [float("inf")]*(n+1)
dp[0] = 0
dp[1] = 0

for i in range(1, n):
  for k_i in range(1, k+1):
    if i+k_i<=n:
      dp[i+k_i] = min(dp[i+k_i], dp[i]+abs(H[i+k_i]-H[i]))
      
print(dp[-1])

Problem: p03161
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1, N):
    h_to = h[i]
    dp[i] = min(
        [
            dp_from + abs(h_to - h_from)
            for dp_from, h_from in zip(
                dp[max(0, i-K):i], h[max(0, i-K):i]
            )
        ]
    )

Failing test case input:
10 3
40 9 20 70 80 10 17 70 135 60

Expected output:
60


Actual output:

Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1, N):
    h_to = h[i]
    dp[i] = min(
        [
            dp_from + abs(h_to - h_from)
            for dp_from, h_from in zip(
                dp[max(0, i-K):i], h[max(0, i-K):i]
            )
        ]
    )

print(dp[-1])

Problem: p03161
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)

dp = [10**10] * (N+1)
dp[0],dp[1] = 0,0

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


Failing test case input:
5 6
25 10 14 70 0 21 9 91 121 60

Expected output:
25


Actual output:
0


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)

dp = [10**10] * (N+1)
dp[0],dp[1] = 0,0

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

Problem: p03161
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = [0 for i in range(N)]
for i in range(1, N):
  D[i] = D[i-1] + abs(A[i-1] - A[i])
  for j in range(2, K + 1):
    if i - j < 0:
      break
    D[i] = min(D[i], D[i-K] + abs(A[i-K] - A[i]))
print(D[-1])

Failing test case input:
5 6
25 10 14 70 80 12 9 91 121 60

Expected output:
55


Actual output:
50


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = [0 for i in range(N)]
for i in range(1, N):
  D[i] = D[i-1] + abs(A[i-1] - A[i])
  for j in range(2, K + 1):
    if i - j < 0:
      break
    D[i] = min(D[i], D[i-j] + abs(A[i-j] - A[i]))
print(D[-1])