Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> v(n), w(n);
  rep(i, n) cin >> v[i] >> w[i];
  
  ll m = min(n, (1 << 9));
  vector<vector<ll>> dp(m, vector<ll>(100001, 0));
  FOR(j, w[0], 100001) dp[0][j] = v[0];
  FOR(i, 1, m) {
    rep(j, 100001) {
      dp[i][j] = dp[(i - 1) / 2][j];
      if (j - w[i] >= 0) chmax(dp[i][j], dp[(i - 1) / 2][j - w[i]] + v[i]);
    }
  }

  ll q;
  cin >> q;
  while (q--) {
    ll vs, l;
    cin >> vs >> l;
    vs--;

    vector<ll> resv, resw;
    while (vs >= m) {
      resv.push_back(v[vs]);
      resw.push_back(w[vs]);
      vs = (vs - 1) / 2;
    }
    vector<ll> resdp(100001, 0);
    rep(i, resv.size()) {
      FORR(j, 100000, resw[i]) {
        chmax(resdp[j], resdp[j - resw[i]] + resv[i]);
      }
    }
    ll ans = 0;
    rep(i, l + 1) {
      chmax(ans, dp[vs][i] + resdp[l - i]);
    }
    cout << ans << '\n';
  }

  




  
  return 0;
}


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