Language: C++

#include<bits/stdc++.h>
#include<math.h>
#include<set>
#include<string>
using namespace std;

//#define int                long long int
#define jaldichal          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                 push_back
#define mk                 make_pair
#define R                  return
#define line               "\n"
#define space              " "
#define all(x)             x.begin(),x.end()
#define w(x)               int x;cin>>x;for(int i=1;i<=x;i++)
#define vi                 vector<int>
#define setbits(x)         __builtin_popcountll(x)
#define ll                 long long 

int n,m;

ll int recursion(ll int a[],int K, int i, ll int previous_taken, ll int* dp){

     if(i >= n){
        return 0;
    }


    if(dp[i]!=-1){
        return dp[i];
    }

    // cout<<"?";
    int res = INT_MAX;
    for(int j =i+1;j<=i+K && j<n;j++){
        res = min(res,abs(previous_taken - a[j]) + recursion(a,K,j,a[j],dp));
    }
    if(res == INT_MAX)
        res =0;
      dp[i] = res;
return  res;
}


void solve()
{
    cin>>n;
    int a[n];
    int K;cin>>K;
    ll int dp[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i]= -1;
    }

   ll int ans = recursion(a,K,0,a[0],dp);
    cout<<ans<<line;
}

signed main()
{    
    jaldichal
    solve();

    return 0;
}



Compiler output:
a.cc: In function 'long long int recursion(long long int*, int, int, long long int, long long int*)':
a.cc:36:18: error: no matching function for call to 'min(int&, long long int)'
   36 |         res = min(res,abs(previous_taken - a[j]) + recursion(a,K,j,a[j],dp));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:36:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   36 |         res = min(res,abs(previous_taken - a[j]) + recursion(a,K,j,a[j],dp));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:36:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |         res = min(res,abs(previous_taken - a[j]) + recursion(a,K,j,a[j],dp));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'void solve()':
a.cc:56:27: error: cannot convert 'int*' to 'long long int*'
   56 |    ll int ans = recursion(a,K,0,a[0],dp);
      |                           ^
      |                           |
      |                           int*
a.cc:22:25: note:   initializing argument 1 of 'long long int recursion(long long int*, int, int, long long int, long long int*)'
   22 | ll int recursion(ll int a[],int K, int i, ll int previous_taken, ll int* dp){
      |                         ^