Language: C++

#include <bits/stdc++.h>
#define int long long int

using namespace std ;

const int N = 2e6 + 100 ;
int n , a[N] , dp[N] , k;

int32_t main(){
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++)cin >> a[i] ;
	for(int i = 2 ; i <= n ; i++){
		dp[i] = 1e18 ;
		for(int j = 1 ; j <= k && i - j ; j++){
		dp[i] = min(abs(a[i - 1] - a[i - 1 - j]) + dp[i - j] , dp[i]) ;
	}
	cout << dp[n] << '\n' ;
	return 0 ;
}
/*
#include <radman/roderc++.h>
                     ....._____
                 .~~~~~////////\\                                                                                           ...
              .:::::////////////\\                                          ....::////////..                              (/\\\\...
           .::::://////   \\\\///\\              .:::://                ..:::::///////////////.                           \\\\\$$$$$$
         \\\\\//////      \\\\///\\           //\\\//////             \\\\\////////////////////.                           ""\\$$$$$$$
         \\\\\////         \\\\////         |||||////////.            \\\\\/////     ~~~~~//////          ...                  "\$$$$
         \\\\\//\         ////|||/          \\\\\/////////            \\\\\//\       ~~~~~//////        (/\\\\...                   .
         \\\\\//\        ////|||/          |||||////*\\///.           \\\\\//\       ~~~~~//////        \\\\\$$$$$$                 .@@@@@.
         \\\\\//\       ////|||/           \\\\\///|\\\////           \\\\\//\       ~~~~~//////         ""\\$$$$$$$               @@@@////\
         \\\\\//\ ____---/|||/            |||||///|\\\\\///.          \\\\\//\       ~~~~~//////             "\$$$$                @@@@\///\
         \\\\\//\--|||||||_-'             \\\\\///|\\\\\////          \\\\\//\       ~~~~~//////                                  ,@@@@|///|
         \\\\\//\|||||_"-\\\\\           |||||///|  ~~~~~///.         \\\\\//\      ~~~~~//////     .@@@@.                    /@@@@@|/////
         \\\\\//\///"""\\\\\\\\          \\\\\///|~~~~[[[////.        \\\\\//\     ~~~~~//////      @@@@@@@@                ..@@@@@.//////
         \\\\\//\    \"""\\\\\\\        |||||///|~~[[[[["\////.       \\\\\//\    ~~~~~//////      '@@@@/////\       .:;@@@@@@@..///////"
         \\\\\//\      \"""\\\\\\       \\\\\///|[[[[*\\\\\////.      \\\\\//\   ~~~~~//////        *@@@\//////\@@@@@@@@..//////////"
         \\\\\//\       \:::\\\\/      |||||///|[[[*   \\\\\\///      \\\\\//\~~~~~///////'            *@@\/////////////////////"
         \\\\\//\        \___\\/       \\\\\///|*       \\\\\/"       \\\\\//\~~////////'                 **"///////////"""
         \\\\\//\                     |||||///|                       \\\\\//\///////"
         \\\\\//\                     \\\\\///|                       \\\\\//\////"
         \\\\\///                    |||||////|                       \\\\\////"
         \\\\\/"                     \\\\\///*                        \\\\\/"
                                     """""*
*/


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:19:2: error: expected '}' at end of input
   19 | }
      |  ^
a.cc:9:15: note: to match this '{'
    9 | int32_t main(){
      |               ^