Language: C++

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll mod = 998244353;
#define EPS 1e-1
#define PI 3.14159265

#define iofile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

ll fastpow(ll base, ll pow)
{
    if (!base)
        return 0;
    if (!pow)
        return 1;
    if (pow == 1)
        return base;
    ll x = fastpow(base, pow / 2) % mod;
    x *= x;
    x %= mod;
    if (pow % 2)
        x *= base;
    return x % mod;
}

ll inverse(ll x)
{
    return fastpow(x, mod - 2) % mod;
}

ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}

void factorize(ll x, map<int, int> &ss)
{
    while (x % 2 == 0)
        ss[2]++, x /= 2;
    for (int i = 3; i <= sqrt(x); i += 2)
        while (x % i == 0)
            ss[i]++, x/= i;
    if (x > 2)
        ss[x]++;
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
ll arr[(int)1e5 + 5];
ll dp[(int)1e5 + 5];

int solve(int idx)
{
    if (idx == n)
        return 0;
    if (dp[idx] != -1)
        return dp[idx];
    int res = 1e9;
    if (idx + 1 < n)
        res = min(res, abs(arr[idx] - arr[idx + 1]) + solve(idx + 1));
    else if (idx + 1 == n)
        res = min(res, solve(idx + 1));
    if (idx + 2 < n)
        res = min(res, abs(arr[idx] - arr[idx + 2]) + solve(idx + 2));
    else if (idx == n)
        res = min(res, solve(idx + 2));
    return dp[idx] = res;
}

int main()
{
    fastio
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0);
    return 0;
}


Compiler output:
a.cc: In function 'int solve(int)':
a.cc:82:18: error: no matching function for call to 'min(int&, long long int)'
   82 |         res = min(res, abs(arr[idx] - arr[idx + 1]) + solve(idx + 1));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:82:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   82 |         res = min(res, abs(arr[idx] - arr[idx + 1]) + solve(idx + 1));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:82:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   82 |         res = min(res, abs(arr[idx] - arr[idx + 1]) + solve(idx + 1));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:86:18: error: no matching function for call to 'min(int&, long long int)'
   86 |         res = min(res, abs(arr[idx] - arr[idx + 2]) + solve(idx + 2));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:86:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   86 |         res = min(res, abs(arr[idx] - arr[idx + 2]) + solve(idx + 2));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
/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:86:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   86 |         res = min(res, abs(arr[idx] - arr[idx + 2]) + solve(idx + 2));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~