Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <array>
#include <map>

using namespace std;
using ll = long long;

map<ll, array<int, 10001>> dp_table;

int main()
{
    ll N;
    array<ll, (1 << 18)> V, W;

    cin >> N;
    for (ll i = 1; i <= N; i++) cin >> V[i] >> W[i];

    ll Q;
    cin >> Q;
    ll ans[10001];

    for (ll i = 1; i <= Q; i++)
    {
        ll K, L;
        cin >> K >> L;

        ll nodes[64];
        ll cnt = 0;
        for (ll j = K; j != 0; j = j / 2) nodes[cnt++] = j;

        for (ll m = cnt - 1; m >= 0; m++)
        {
            ll j = nodes[m];
            if (dp_table.find(j) != dp_table.end()) continue;

            if (j == 1)
            {
                dp_table[j] = array<int, 10001>();
                dp_table[j].fill(0);
            }
            else
            {
                dp_table[j] = dp_table[j / 2];
            }
            auto& dp = dp_table[j];

            ll v = V[j];
            ll w = W[j];
            for (ll k = L - w; k >= 0; k--) dp[k + w] = max(dp[k + w], dp[k] + v);
        }

        ll maxv = 0;
        for (ll k = 0; k <= L; k++) maxv = max(maxv, dp[k]);

        ans[i] = maxv;
    }

    for (ll i = 1; i <= Q; i++) cout << ans[i] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:60: error: no matching function for call to 'max(std::array<int, 10001>::value_type&, ll)'
   52 |             for (ll k = L - w; k >= 0; k--) dp[k + w] = max(dp[k + w], dp[k] + v);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:52:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   52 |             for (ll k = L - w; k >= 0; k--) dp[k + w] = max(dp[k + w], dp[k] + v);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:52:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   52 |             for (ll k = L - w; k >= 0; k--) dp[k + w] = max(dp[k + w], dp[k] + v);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:56:54: error: 'dp' was not declared in this scope
   56 |         for (ll k = 0; k <= L; k++) maxv = max(maxv, dp[k]);
      |                                                      ^~