Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

    for i in range(N):
        if i == 0:
            pass
        elif i == 1:
            dp[1] = abs(h[1]-h[0])
        else:
            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__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):

def main():
    with open("input.txt", "r") as f:
        t = f.readlines()
        N = int(t[0].split()[0])
        K = int(t[0].split()[1])
        h = t[1].split()
        h = [int(i) for i in h]
#    N, K  = map(int, input().split())
#    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

    for i in range(N):
        if i == 0:
            pass
        elif i == 1:
            dp[i] = h[0]
        else:
            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__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):

def main():
    with open("input.txt", "r") as f:
        t = f.readlines()
        N = int(t[0].split()[0])
        K = int(t[0].split()[1])
        h = t[1].split()
        h = [int(i) for i in h]
#    N, K  = map(int, input().split())
#    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

    for i in range(N):
        if i == 0:
            pass
        elif i == 1:
            dp[i] = h[1]
        else:
            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__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

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

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

    for i in range(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__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    dp = [10**9] * max(N,K)
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
#    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
#    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

    for i in range(N):
#        j = 0
        L = min(K, i)
        m = []
        for j in range(L+1):
            m.append(dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = min(m)
#        while j <= L:
#            #print(i)
#            if dp[i] > dp[i-j] + abs(h[i]-h[i-j]):
#                dp[i] = dp[i-j] + abs(h[i]-h[i-j])
#            j += 1
    print(dp[N-1])

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
#    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
#    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float("inf")] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
#    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):

def main():
    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

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

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N, K  = map(int, input().split())
    h = [int(i) for i in input().split()]
    dp = [10**5] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

if __name__ == "__main__":
    main()