Language: C++

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
vector<int> h;
int t1,t2,t3;
vector<long int> ans(100000, -2);
long int cost(long int n,int k)
{
	if((ans[n]!=-2))
    {
        //cout<<n<<' '<<ans[n]<<endl;
		return ans[n];
    }
	if(n==1)
	{
		ans[1]=0;
      	//cout<<n<<' '<<ans[n]<<endl;
		return ans[1];
	}
	if(n==2)
	{
		ans[2]=abs(h[1]-h[2]);
        //cout<<n<<' '<<ans[n]<<endl;
		return ans[2];
	}/*
  	int p1=cost(n-2);
  	cout<<endl<<p1<<"This is cost(n-2)"<<n<<endl;
  	cout<<endl<<abs(h[n]-h[n-2])<<"This is abs(h[n]-h[n-2])"<<endl;
  	t1=cost(n-2)+abs(h[n]-h[n-2]);
    t2=cost(n-1)+abs(h[n]-h[n-1]);
  	cout<<endl<<t1<<"This is t1"<<endl;
  	cout<<endl<<t2<<"This is t2"<<endl;
	t3=min(t1,t2);
  	cout<<endl<<t3<<"This is t3"<<endl;*/
  long int i;
  int x;
  int mi=32000;
  	for(i=n-1, x=1;i>=1 && x<=k;i--,x++)
    {
    	mi=min(mi,cost(n-x,k)+abs(h[n]-h[n-x]));
    }
  	//ans[n]=min(cost(n-2)+abs(h[n]-h[n-2]),cost(n-1)+abs(h[n]-h[n-1]));
	//cout<<n<<' '<<ans[n]<<endl;
  	ans[n]=mi;
  	return ans[n];
  	//return min(cost(n-2)+abs(h[n]-h[n-2]),cost(n-1)+abs(h[n]-h[n-1]));
}
int main()
{
	long int n,i;
	int h1,k;
	h.push_back(0);
	cin>>n>>k;

	for(i=1;i<=n;i++)
	{
		cin>>h1;
		h.push_back(h1);
        //cout<<ans[i];
	}
	cout<<cost(n,k);
  //cout<<min(2,3);

  return 0;
}



Compiler output:
a.cc: In function 'long int cost(long int, int)':
a.cc:40:15: error: no matching function for call to 'min(int&, long int)'
   40 |         mi=min(mi,cost(n-x,k)+abs(h[n]-h[n-x]));
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:40:15: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
   40 |         mi=min(mi,cost(n-x,k)+abs(h[n]-h[n-x]));
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:40:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   40 |         mi=min(mi,cost(n-x,k)+abs(h[n]-h[n-x]));
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~