Language: C++

#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
							for(int j=0;j<n;j++){   \
								cout<<a[i][j]<<" "; \
							}                       \
							cout<<endl;             \
						}
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define len(s) (ll)(s.size())
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
	fast_io()
 

	ll t;
	//cin>>t;
	t=1;
	while(t--){
		ll n,k;
		cin>>n>>k;
		ll h[n],dp[n];
		rep(n){
			cin>>h[i];
		}
		mset(dp,0);
		dp[1]=abs(h[1]-h[0]);
		ll ans;
		fori(i,2,n-1){
			ans=LLONG_MAX;
			fori(j,1,min(k,i)){
				ans=min(ans,dp[i-j]+abs(h[i]-h[i-j]));
			}
			dp[i]=ans;
		}
		cout<<dp[n-1];
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:37: error: no matching function for call to 'min(long long int&, int&)'
   67 |                         fori(j,1,min(k,i)){
      |                                  ~~~^~~~~
a.cc:17:37: note: in definition of macro 'fori'
   17 | #define fori(i,a,b) for(auto i=a;i<=b;i++)
      |                                     ^
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:67:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   67 |                         fori(j,1,min(k,i)){
      |                                  ~~~^~~~~
a.cc:17:37: note: in definition of macro 'fori'
   17 | #define fori(i,a,b) for(auto i=a;i<=b;i++)
      |                                     ^
/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:67:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   67 |                         fori(j,1,min(k,i)){
      |                                  ~~~^~~~~
a.cc:17:37: note: in definition of macro 'fori'
   17 | #define fori(i,a,b) for(auto i=a;i<=b;i++)
      |                                     ^