Language: C++

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int f[100000];
int dp[100000];
int main() {
	int n, k;
	cin >> n >> k;
	memset(dp, 0x3f, sizeof(dp));
	for(int i=0; i<n; i++) {
		scanf("%d", &f[i]);
	}
	dp[0] = 0;
	for(int i=1; i<k; i++) {
		for(int j=i; j>=0; j--) {
			dp[i] = min(dp[i], dp[i - j] + fabs(f[i] - f[i - j]));
		}
	}
	for(int i=k; i<n; i++) {
		for(int j=1; j<=k; j++) {
			dp[i] = min(dp[i], dp[i - j] + fabs(f[i] - f[i - j]));
		}
	}
	cout << dp[n - 1] << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:36: error: no matching function for call to 'min(int&, __gnu_cxx::__enable_if<true, double>::__type)'
   18 |                         dp[i] = min(dp[i], dp[i - j] + fabs(f[i] - f[i - j]));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:18:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
   18 |                         dp[i] = min(dp[i], dp[i - j] + fabs(f[i] - f[i - j]));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
a.cc:23:36: error: no matching function for call to 'min(int&, __gnu_cxx::__enable_if<true, double>::__type)'
   23 |                         dp[i] = min(dp[i], dp[i - j] + fabs(f[i] - f[i - j]));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:23:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
   23 |                         dp[i] = min(dp[i], dp[i - j] + fabs(f[i] - f[i - j]));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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