Language: C++

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};


string bist(ll n, ll d){
    Radix r;
    string f = r.to(n, 2);
    if(sz(f) < d){
        f = '0' + f;
    }
    return f;
}

int main(){
    int N; cin >> N;
    vll w(N+1), v(N+1);
    rep(i, 1, N+1){
        cin >> v[i] >> w[i];
    }
    ll th = 4095;
    ll x = min(th, N);

    vvll pdp(x+1, vll(100001));
    rep(i, 0, 100001){
        pdp[0][i] = 0;
    }
    rep(i, 0, 100001){
        if(w[1] <= i){
            pdp[1][i] = v[1];
        }else{
            pdp[1][i] = 0;
        }
    }
    rep(i, 2, x+1){
        rep(j, 0, 100001){
            ll k = i/2;
            if(j >= w[i]){pdp[i][j] = max(pdp[k][j], pdp[k][j-w[i]]+v[i]);}
            else{pdp[i][j] = pdp[k][j];}
        }
    }
    ll q; cin >> q;
    rep(i, 0, q){
        ll V, L; cin >> V >> L;
        if(V <= th){
            prt(pdp[V][L]);
            prt(endl);
        }else{
            vll b(0);
            while(V > th){
                b.emplace_back(V);
                V = V/2;
            }
            ll s = sz(b);
            ll ma = 0;
            rep(j, 0, pow(2, s)){
                string m = bist(j, s);
                ll lf = L;
                ll vl = 0;
                bool z = true;
                rep(k, 0, s){
                    if(m[k] == '1'){
                        lf -= w[b[k]];
                        if(lf < 0){
                            z = false;
                            break;
                        }
                        vl += v[b[k]];
                    }
                }
                if(z){
                    vl += pdp[V][lf];
                }
                ma = max(ma, vl);
            }
            prtl(ma);
        }
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:79:15: error: no matching function for call to 'min(ll&, int&)'
   79 |     ll x = min(th, N);
      |            ~~~^~~~~~~
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: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:79:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   79 |     ll x = min(th, N);
      |            ~~~^~~~~~~
/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:79:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   79 |     ll x = min(th, N);
      |            ~~~^~~~~~~