Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = 1<<32

def solve(N: int, K: int, h: "List[int]"):
    dp = [INF] * (N+2)
    dp[0] = 0
    dp[1] = abs(h[1]-h[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+j]-h[i]))
            # if(i+1 < N):
            #     dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
            # if(i+2 < N):
            #     dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))

    print(dp[N-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    INF = 10000000000
    dp = [INF]* (N+1)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        for t in range(1,K+1):
            if(i-t >= 0):
                dp[i] = min(dp[i], dp[i-t]+abs(h[i]-h[i-t]))
        # print(dp)
    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    INF = 10000000000
    dp = [INF]* (N+1)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        for t in range(1,K+1):
            if(i-t >= 0):
                dp[i] = min(dp[i], dp[i-t]+abs(h[i]-h[i-t]))
        # print(dp)
    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    INF = 10000000000
    dp = [INF]* (N+1)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        for t in range(1,K+1):
            if(i-t >= 0):
                dp[i] = min(dp[i], dp[i-t]+abs(h[i]-h[i-t]))
        # print(dp)
    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    INF = 10000000000
    dp = [INF]* (N+1)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        for t in range(1,K+1):
            if(i-t >= 0):
                dp[i] = min(dp[i], dp[i-t]+abs(h[i]-h[i-t]))
        # print(dp)
    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    INF = 10000000000
    dp = [INF]* (N+1)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        for t in range(1,K+1):
            if(i-t >= 0):
                dp[i] = min(dp[i], dp[i-t]+abs(h[i]-h[i-t]))
        # print(dp)
    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()