Language: C++

#include <bits/stdc++.h>
using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int v[303030];
int w[303030];
void solve(){
    int n;
  	scanf("%d",&n);
    REP(i,n) scanf("%d %d",&v[i],&w[i]);

    auto check = [&](ll& W, vec<int>& o){
        int n2=o.size();
		vector<P> wv1,wv2;
		for(ll bit=0;bit < (1LL<<(n2/2));bit++){
			ll ww=0,vv=0;
			bool flag=true;
			REP(i,n2/2){
				if((bit&(1LL<<i))!=0){
					ww+=w[o[i]];
					vv+=v[o[i]];
					if(ww>W){
						flag=false;
						break;
					}
				}
			}
			if(flag) wv1.push_back(make_pair(ww,vv));
		}

		for(ll bit=0;bit < (1LL<<(n2-n2/2));bit++){
			ll ww=0,vv=0;
			bool flag=true;
			REP(i,n2-n2/2){
				if((bit&(1LL<<i))!=0){
					ww+=w[o[i+n2/2]];
					vv+=v[o[i+n2/2]];
					if(ww>W){
						flag=false;
						break;
					}
				}
			}
			if(flag) wv2.push_back(make_pair(ww,vv));
		}
		sort(all(wv1));
		sort(all(wv2));
 
		ll ans=0LL;
        int t = 0;
        ll ma = 0;
        REP2(i,wv1.size()) {
            while(t < wv2.size() && wv1[i].first + wv2[t].first <= W) {
                ma = max(ma, wv2[t++].second);
            }
            ans = max(ans, ma + wv1[i].second);
        }
		printf("%lld\n",ans);
    };

    int q;
    scanf("%d",&q);
    REP(i,q){
        int vv,max_w;
        scanf("%d %d",&vv,&max_w);
        vec<int> o;
        while(vv){
            o.push_back(vv-1);
            vv/=2;
        }
        //cout<<i<<en;
        check(max_w,o);
    }
}

int main() {
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:129:14: error: no match for call to '(solve()::<lambda(ll&, vec<int>&)>) (int&, vec<int>&)'
  129 |         check(max_w,o);
      |         ~~~~~^~~~~~~~~
a.cc:69:18: note: candidate: 'solve()::<lambda(ll&, vec<int>&)>' (near match)
   69 |     auto check = [&](ll& W, vec<int>& o){
      |                  ^
a.cc:69:18: note:   conversion of argument 1 would be ill-formed:
a.cc:129:15: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int'
  129 |         check(max_w,o);
      |               ^~~~~