Language: C++

//g++  5.4.0

#include <iostream>
#include<cmath>
#include<cassert>
using namespace std;
int main()
{
    
    //std::cout << "Hello, world!\n";
    long long n,k;cin>>n>>k;
    long long ar[n],mem[n] = {0};
    for(int i = 0;i < n;i++){
        cin>>ar[i];// = 1e5;
    }
    mem[0] = 0;
    mem[1] = (int)abs(ar[1]-ar[0]);
    for(int i = 2;i < n;i++){
        mem[i] = abs(ar[i] - ar[max(0,i-k)]) + mem[max(0,i-k)];
        for(int j = max(0,i-k);j < i;j++){
            //int x = 0;
            //assert(0<j && j<n);
            mem[i] = min(mem[i],(int)abs(ar[i]-ar[i-j])+mem[i-j]);
        }
               //mem[i] = min(mem[i],abs(ar[i] - mem[i-j]));
    }
    
    cout<<mem[n-1]<<"\n";
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:36: error: no matching function for call to 'max(int, long long int)'
   19 |         mem[i] = abs(ar[i] - ar[max(0,i-k)]) + mem[max(0,i-k)];
      |                                 ~~~^~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/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:19:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   19 |         mem[i] = abs(ar[i] - ar[max(0,i-k)]) + mem[max(0,i-k)];
      |                                 ~~~^~~~~~~
/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
a.cc:19:55: error: no matching function for call to 'max(int, long long int)'
   19 |         mem[i] = abs(ar[i] - ar[max(0,i-k)]) + mem[max(0,i-k)];
      |                                                    ~~~^~~~~~~
/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:19:55: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   19 |         mem[i] = abs(ar[i] - ar[max(0,i-k)]) + mem[max(0,i-k)];
      |                                                    ~~~^~~~~~~
/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
a.cc:20:24: error: no matching function for call to 'max(int, long long int)'
   20 |         for(int j = max(0,i-k);j < i;j++){
      |                     ~~~^~~~~~~
/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:20:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   20 |         for(int j = max(0,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