Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb emplace_back
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}


int binsch(int key, const vector<pair<int,int>>& lv){
  // set value
  int ng = sz(lv); int ok = 0;
  while(abs(ok-ng)>1){
    int mid = (ok+ng)/2;
    if(lv[mid].first<=key) ok = mid;
    else ng = mid;
  }
  return lv[ok].second;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N; cin >> N;
  vector<pair<int,int>> VW(N+1); rep(i,N) cin >> VW[i+1].first >> VW[i+1].second;
  int Q; cin >> Q;
  rep(q,Q){
    int v,l; cin >> v >> l;
    vector<int> vv;
    vector<int> ll;
    int now = v;
    while(now){
      vv.pb(VW[now].first);
      ll.pb(VW[now].second);
      now >>= 1;
    }
    int n = sz(vv);
    vector<int> av, al, bv, bl;
    for(int i=0;i<n;i++){
      if(i<n/2){
        av.pb(vv[i]);
        al.pb(ll[i]);
      }
      else{
        bv.pb(vv[i]);
        bl.pb(ll[i]);
      }
    }
    vector<pair<int,int>> alv;
    for(int i=0;i<(1<<n/2);i++){
      vector<bool> use(n/2, false);
      int now = i;
      rep(j,n/2){
        use[j] = now&1;
        now>>=1;
      }
      int sv=0,sl=0;
      rep(j,n/2){
        if(use[j]){
          sv += av[j];
          sl += al[j];
        }
      }
      if(sl<=l) alv.pb({sl,sv});
    }
    int x = n-n/2;
    vector<pair<int,int>> blv;
    for(int i=0;i<(1<<x);i++){
      vector<bool> use(x, false);
      int now = i;
      rep(j,x){
        use[j] = now&1;
        now>>=1;
      }
      int sv=0,sl=0;
      rep(j,x){
        if(use[j]){
          sv += bv[j];
          sl += bl[j];
        }
      }
      if(sl<=l) blv.pb({sl,sv});
    }
    sort(all(alv));
    sort(all(blv));
    int mxva=-1;
    rep(i,sz(alv)){
      if(mxva>alv[i].second){
        alv[i].first=1000000;
      }
      else{
        mxva = alv[i].second;
      }
    }
    int mxvb=-1;
    rep(i,sz(blv)){
      if(mxvb>blv[i].second){
        blv[i].first=1000000;
      }
      else{
        mxvb = blv[i].second;
      }
    }
    sort(all(alv));
    sort(all(blv));
    int ans = 0;
    rep(i,sz(alv)){
      int lll = alv[i].first;
      int vvv = alv[i].second;
      if(lll>l) continue;
      int vvvv = binsch(l-lll,blv);
      chmax(ans, vvv+vvvv);
    }
    cout << ans << '\n';
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:23: error: no matching function for call to 'std::vector<std::pair<int, int> >::emplace_back(<brace-enclosed initializer list>)'
   69 |       if(sl<=l) alv.pb({sl,sv});
      |                 ~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/vector:72,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/vector.tcc:111:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; reference = std::pair<int, int>&]'
  111 |       vector<_Tp, _Alloc>::
      |       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:111:7: note:   candidate expects 0 arguments, 1 provided
a.cc:87:23: error: no matching function for call to 'std::vector<std::pair<int, int> >::emplace_back(<brace-enclosed initializer list>)'
   87 |       if(sl<=l) blv.pb({sl,sv});
      |                 ~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:111:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; reference = std::pair<int, int>&]'
  111 |       vector<_Tp, _Alloc>::
      |       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:111:7: note:   candidate expects 0 arguments, 1 provided