Language: C++

#include <iostream>
#include <cstdio>
using namespace std;

int n, k, h[100001], f[100001];
int abs(int a) {return (a>0)?a:(-a);}
int way(int a)
{
    int mins = INT_MAX, minp = 0;
    for (int i = ((a-k > 0) ? (a-k) : 1);  i < a; i++)
    {
        if (f[i] + abs(h[a] - h[i]) < mins)
        {
            mins = f[i] + abs(h[a] - h[i]);
            minp = i;
        }
    }
    return minp;
}
int main()
{
    //freopen("FROG2.inp", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(false);
    cout.tie(false);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    f[1] = 0, f[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; i++)
    {
        f[i] = f[way(i)] + abs(h[i] - h[way(i)]);
        cout << way(i) << " " << f[i] << endl;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << f[i] << " ";
    }
    cout << f[n];
    return 0;
}


Compiler output:
a.cc: In function 'int way(int)':
a.cc:9:16: error: 'INT_MAX' was not declared in this scope
    9 |     int mins = INT_MAX, minp = 0;
      |                ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <cstdio>
  +++ |+#include <climits>
    3 | using namespace std;
a.cc:15:13: error: 'minp' was not declared in this scope; did you mean 'mins'?
   15 |             minp = i;
      |             ^~~~
      |             mins
a.cc:18:12: error: 'minp' was not declared in this scope; did you mean 'mins'?
   18 |     return minp;
      |            ^~~~
      |            mins
a.cc: In function 'int main()':
a.cc:24:12: error: no matching function for call to 'std::basic_istream<char>::tie(bool)'
   24 |     cin.tie(false);
      |     ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_ios.h:299:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]'
  299 |       tie() const
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:299:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/basic_ios.h:311:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:311:43: note:   no known conversion for argument 1 from 'bool' to 'std::basic_ostream<char>*'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
a.cc:25:13: error: no matching function for call to 'std::basic_ostream<char>::tie(bool)'
   25 |     cout.tie(false);
      |     ~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/basic_ios.h:299:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]'
  299 |       tie() const
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:299:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/basic_ios.h:311:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:311:43: note:   no known conversion for argument 1 from 'bool' to 'std::basic_ostream<char>*'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~