Language: C++

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << x << '\n'
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const llabs MAX_N = 1e5 + 100;
ll N;
ll K;
ll dp[MAX_N];
ll h[MAX_N];

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 0; i < N; i++)
      cin >> h[i+1];

  dp[1] = 0;
  dp[2]= abs(h[2]- h[1]);

  for (int i = 3; i < N+1; i++) {
    ll mTotal = MAX_N;
    for (int k = 1; k < min(i, K+1); k++){
      mTotal = min(mTotal, dp[i-k] + abs(h[i]-h[i-k]));
    }
    dp[i] = mTotal;         
  }
    
  cout << dp[N]<<endl;
  return 0;
}

Compiler output:
a.cc:16:7: error: 'llabs' does not name a type
   16 | const llabs MAX_N = 1e5 + 100;
      |       ^~~~~
a.cc:19:7: error: 'MAX_N' was not declared in this scope
   19 | ll dp[MAX_N];
      |       ^~~~~
a.cc:20:6: error: 'MAX_N' was not declared in this scope
   20 | ll h[MAX_N];
      |      ^~~~~
a.cc: In function 'int main()':
a.cc:28:14: error: 'h' was not declared in this scope
   28 |       cin >> h[i+1];
      |              ^
a.cc:30:3: error: 'dp' was not declared in this scope; did you mean 'dup'?
   30 |   dp[1] = 0;
      |   ^~
      |   dup
a.cc:31:14: error: 'h' was not declared in this scope
   31 |   dp[2]= abs(h[2]- h[1]);
      |              ^
a.cc:34:17: error: 'MAX_N' was not declared in this scope
   34 |     ll mTotal = MAX_N;
      |                 ^~~~~
a.cc:35:28: error: no matching function for call to 'min(int&, ll)'
   35 |     for (int k = 1; k < min(i, K+1); k++){
      |                         ~~~^~~~~~~~
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:35:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   35 |     for (int k = 1; k < min(i, K+1); k++){
      |                         ~~~^~~~~~~~
/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:35:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   35 |     for (int k = 1; k < min(i, K+1); k++){
      |                         ~~~^~~~~~~~