Language: C++

#include <bits/stdc++.h>

using namespace std;

const long long INF = 10000000000000000;
map<long long, long long> memo;
long long n;
int a, b, c, d;

long long rec(long long n, long long x) {
    if (n == 0) return 0;
    if (memo.count(n)) return memo[n];
    long long res = n;
    if (n < 0) {
        res = min(res, rec(memo, n - (- 1), a, b, c, d, --x));
    } else {
        for (int i = 0; i < 4; i++) {
            if (i == 0) {
                res = min(res, rec(memo, n - (x * 5), a, b, c, d, x * 5));
            } else if (i == 1) {
                res = min(res, rec(memo, n - (x * 3), a, b, c, d, x * 3));
            } else if (i == 2) {
                res = min(res, rec(memo, n - (x * 2), a, b, c, d, x * 2));
            } else if (i == 3) {
                res = min(res, rec(memo, n - 1, a, b, c, d, ++x));
            }
        }
    }
    memo[n] = res;
    return memo[n];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> n;
        cin >> a >> b >> c >> d;
        memo.clear();
        memo[0] = 0;
        memo[1] = d;
        cout << rec(n, memo[1]) << '\n';
    }
    return 0;
}

Compiler output:
a.cc: In function 'long long int rec(long long int, long long int)':
a.cc:15:28: error: cannot convert 'std::map<long long int, long long int>' to 'long long int'
   15 |         res = min(res, rec(memo, n - (- 1), a, b, c, d, --x));
      |                            ^~~~
      |                            |
      |                            std::map<long long int, long long int>
a.cc:10:25: note:   initializing argument 1 of 'long long int rec(long long int, long long int)'
   10 | long long rec(long long n, long long x) {
      |               ~~~~~~~~~~^
a.cc:19:36: error: cannot convert 'std::map<long long int, long long int>' to 'long long int'
   19 |                 res = min(res, rec(memo, n - (x * 5), a, b, c, d, x * 5));
      |                                    ^~~~
      |                                    |
      |                                    std::map<long long int, long long int>
a.cc:10:25: note:   initializing argument 1 of 'long long int rec(long long int, long long int)'
   10 | long long rec(long long n, long long x) {
      |               ~~~~~~~~~~^
a.cc:21:36: error: cannot convert 'std::map<long long int, long long int>' to 'long long int'
   21 |                 res = min(res, rec(memo, n - (x * 3), a, b, c, d, x * 3));
      |                                    ^~~~
      |                                    |
      |                                    std::map<long long int, long long int>
a.cc:10:25: note:   initializing argument 1 of 'long long int rec(long long int, long long int)'
   10 | long long rec(long long n, long long x) {
      |               ~~~~~~~~~~^
a.cc:23:36: error: cannot convert 'std::map<long long int, long long int>' to 'long long int'
   23 |                 res = min(res, rec(memo, n - (x * 2), a, b, c, d, x * 2));
      |                                    ^~~~
      |                                    |
      |                                    std::map<long long int, long long int>
a.cc:10:25: note:   initializing argument 1 of 'long long int rec(long long int, long long int)'
   10 | long long rec(long long n, long long x) {
      |               ~~~~~~~~~~^
a.cc:25:36: error: cannot convert 'std::map<long long int, long long int>' to 'long long int'
   25 |                 res = min(res, rec(memo, n - 1, a, b, c, d, ++x));
      |                                    ^~~~
      |                                    |
      |                                    std::map<long long int, long long int>
a.cc:10:25: note:   initializing argument 1 of 'long long int rec(long long int, long long int)'
   10 | long long rec(long long n, long long x) {
      |               ~~~~~~~~~~^