Language: C++

#include <bits/stdc++.h>
 
#define ll long long
#define Add_Speed ios_base::sync_with_stdio(0);cin.tie(0);
#define ins insert
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define sz size()
#define s second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define inf (int)1e9
#define gcd(a, b) __gcd(a, b)
#define int ll
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

const int maxn = (int)1e5 + 17;
const int maxm = (int)15e2 + 7;
const int minn = (int)1e4 + 7;
const int mod = (int)1e9 + 7;
const long double PI = acos(-1);
const int P = (int)1e5 + 7;

int n, k, a[maxn], dp[maxn];

main () {
 
    Add_Speed

    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    memset(dp, mod, sizeof(dp));
    dp[1] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = max(1, i - k); j < i; j++){
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n];
    
}

Compiler output:
a.cc:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main () {
      | ^~~~
a.cc: In function 'int main()':
a.cc:41:24: error: no matching function for call to 'max(int, long long int)'
   41 |         for(int j = max(1, i - k); j < i; j++){
      |                     ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:41:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   41 |         for(int j = max(1, i - k); j < i; j++){
      |                     ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:41:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   41 |         for(int j = max(1, i - k); j < i; j++){
      |                     ~~~^~~~~~~~~~