criyle/codenet-compile-errors huggingface dataset:
Language: C++

int main() {
	int N;
	cin >> N;
	vector<int>V(N);
	vector<int>W(N);
	for (int n = 0; n < N; ++n) {
		cin >> V[n] >> W[n];
	}
 
	int Q;
	cin >> Q;
	vector<int>v(Q);
	vector<int>L(Q);
	for (int n = 0; n < Q; ++n) {
		cin >> v[n] >> L[n];
	}
	int Lmax = 0;
	for (int n = 0; n < Q; ++n) {
		Lmax = max(Lmax, L[n]);
	}
	//DP
	//vector<vector<int> > dp(100+ 1, vector<int>(100 + 1, 0));
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:9: error: 'cin' was not declared in this scope
    3 |         cin >> N;
      |         ^~~
a.cc:4:9: error: 'vector' was not declared in this scope
    4 |         vector<int>V(N);
      |         ^~~~~~
a.cc:4:16: error: expected primary-expression before 'int'
    4 |         vector<int>V(N);
      |                ^~~
a.cc:5:16: error: expected primary-expression before 'int'
    5 |         vector<int>W(N);
      |                ^~~
a.cc:7:24: error: 'V' was not declared in this scope
    7 |                 cin >> V[n] >> W[n];
      |                        ^
a.cc:7:32: error: 'W' was not declared in this scope
    7 |                 cin >> V[n] >> W[n];
      |                                ^
a.cc:12:16: error: expected primary-expression before 'int'
   12 |         vector<int>v(Q);
      |                ^~~
a.cc:13:16: error: expected primary-expression before 'int'
   13 |         vector<int>L(Q);
      |                ^~~
a.cc:15:24: error: 'v' was not declared in this scope
   15 |                 cin >> v[n] >> L[n];
      |                        ^
a.cc:15:32: error: 'L' was not declared in this scope
   15 |                 cin >> v[n] >> L[n];
      |                                ^
a.cc:19:34: error: 'L' was not declared in this scope
   19 |                 Lmax = max(Lmax, L[n]);
      |                                  ^
a.cc:19:24: error: 'max' was not declared in this scope; did you mean 'Lmax'?
   19 |                 Lmax = max(Lmax, L[n]);
      |                        ^~~
      |                        Lmax
Language: C++

int main() {
	int N;
	cin >> N;
	vector<int>V(N);
	vector<int>W(N);
	for (int n = 0; n < N; ++n) {
		cin >> V[n] >> W[n];
	}
 
	int Q;
	cin >> Q;
	vector<int>v(Q);
	vector<int>L(Q);
	for (int n = 0; n < Q; ++n) {
		cin >> v[n] >> L[n];
	}
	int Lmax = 0;
	for (int n = 0; n < Q; ++n) {
		Lmax = max(Lmax, L[n]);
	}
	//DP
	vector<vector<int> > dp(100+ 1, vector<int>(100 + 1, 0));
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:9: error: 'cin' was not declared in this scope
    3 |         cin >> N;
      |         ^~~
a.cc:4:9: error: 'vector' was not declared in this scope
    4 |         vector<int>V(N);
      |         ^~~~~~
a.cc:4:16: error: expected primary-expression before 'int'
    4 |         vector<int>V(N);
      |                ^~~
a.cc:5:16: error: expected primary-expression before 'int'
    5 |         vector<int>W(N);
      |                ^~~
a.cc:7:24: error: 'V' was not declared in this scope
    7 |                 cin >> V[n] >> W[n];
      |                        ^
a.cc:7:32: error: 'W' was not declared in this scope
    7 |                 cin >> V[n] >> W[n];
      |                                ^
a.cc:12:16: error: expected primary-expression before 'int'
   12 |         vector<int>v(Q);
      |                ^~~
a.cc:13:16: error: expected primary-expression before 'int'
   13 |         vector<int>L(Q);
      |                ^~~
a.cc:15:24: error: 'v' was not declared in this scope
   15 |                 cin >> v[n] >> L[n];
      |                        ^
a.cc:15:32: error: 'L' was not declared in this scope
   15 |                 cin >> v[n] >> L[n];
      |                                ^
a.cc:19:34: error: 'L' was not declared in this scope
   19 |                 Lmax = max(Lmax, L[n]);
      |                                  ^
a.cc:19:24: error: 'max' was not declared in this scope; did you mean 'Lmax'?
   19 |                 Lmax = max(Lmax, L[n]);
      |                        ^~~
      |                        Lmax
a.cc:22:23: error: expected primary-expression before 'int'
   22 |         vector<vector<int> > dp(100+ 1, vector<int>(100 + 1, 0));
      |                       ^~~
Language: C++

#include "bits/stdc++.h"

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>V(N);
	vector<int>W(N);
	for (int n = 0; n < N; ++n) {
		cin >> V[n] >> W[n];
	}

	int Q;
	cin >> Q;
	vector<int>v(Q);
	vector<int>L(Q);
	for (int n = 0; n < Q; ++n) {
		cin >> v[n] >> L[n];
	}
	int Lmax = 0;
	for (int n = 0; n < Q; ++n) {
		Lmax = max(Lmax, L[n]);
	}
	//DP

	if (false) {
		for (int n = 0; n <= N; ++n) {
			for (int m = 0; m <= Lmax; ++m) {
				cout << dp[n][m] << "_";
			}
			cout << endl;
		}
	}

	for (int n = 0; n < Q; ++n) {
		cout << dp[v[n]][L[n]] << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:41: error: 'dp' was not declared in this scope; did you mean 'dup'?
   30 |                                 cout << dp[n][m] << "_";
      |                                         ^~
      |                                         dup
a.cc:37:25: error: 'dp' was not declared in this scope; did you mean 'dup'?
   37 |                 cout << dp[v[n]][L[n]] << endl;
      |                         ^~
      |                         dup
Language: C++

#include <bits\stdc++.h>

using namespace std;

int main() {
  int N, Q;
  cin >> N;
  vector<int> V(N + 1), W(N + 1);
  for (int i = 1; i <= N; ++i) cin >> V[i] >> W[i];
  cin >> Q;
  constexpr int b = 9;
  vector<pair<int, int>> l1, l2, tmp;
  while (Q--) {
    int v, L;
    cin >> v >> L;
    l1.clear();
    l2.clear();
    auto gen = [&](vector<pair<int, int>> &l, int thr) {
      l.emplace_back(0, 0);
      while (v >= thr) {
        int p1 = 0, p2 = 0;
        while (p1 < l.size() || p2 < l.size()) {
          pair<int, int> nxt;
          if (p1 < l.size() && l[p1].first < l[p2].first + W[v])
            nxt = l[p1++];
          else
            nxt = {l[p2].first + W[v], l[p2++].second + V[v]};
          if (tmp.empty() || tmp.back().second > nxt.second) tmp.push_back(nxt);
        }
        v /= 2;
        l.swap(tmp);
        tmp.clear();
      }
    };
    gen(l1, 1 << b);
    gen(l2, 1);
    int p1 = 0, p2 = 0;
    while (p2 + 1 < l2.size() && l1[p1].first + l2[p2 + 1].first <= L) p2++;
    int ans = l1[p1].second + l2[p2].second;
    while (++p1 < l1.size() && l1[p1].first <= L) {
      while (l1[p1].first + l2[p2].first > L) p2--;
      ans = max(ans, l1[p1].second + l2[p2].second);
    }
    cout << ans << "\n";
  }
  return 0;
}


Compiler output:
a.cc:1:10: fatal error: bits\stdc++.h: No such file or directory
    1 | #include <bits\stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

int dep(int n){
    int ret = 0;
    while(n >= 2){
        n /= 2;
        ret++;
    }
    return ret;
}

int func(int n,int j){
    while(j--) n /= 2;
    return n;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    int n; cin >> n;
    int v[n+1],w[n+1];
    REPS(i,n) cin >> v[i] >> w[i];
    int q; cin >> q;
    int M_L = 0;
    int t[q], l[q];
    REP(i,q){
        cin >> t[i] >> l[i];
        chmax(M_L,l[i]);
    }
    //半分全列挙
    int V = min((1ll << 9)-1, n);
    vector<vector<int>> dp(V+1,vector<int>(M_L+1,0));
    REPS(i,V) REP(j,M_L+1){
        chmax(dp[i][j], dp[i/2][j]);
        if(j - w[i] > -1) chmax(dp[i][j], dp[i/2][j-w[i]] + v[i]);
    }
    int z, o, ans, hoge[9];
    REP(i,q){
        if(t[i] <= V) cout << dp[t[i]][l[i]] << '\n';
        else{
            z = dep(t[i]) - 8;
            o = func(t[i],z);
            ans = 0;
            REP(i,z) hoge[i] = func(t[i],j);
            for(int b = 0; b < (1ll << z); b++){
                int sumw = 0;
                int sumv = 0;
                REP(j,z) if((b >> j) & 1){
                    sumw += w[hoge[j]];
                    sumv += v[hoge[j]];
                }
                if(l[i]-sumw > -1) chmax(ans, dp[o][l[i]-sumw] + sumv);
            }
            cout << ans << '\n';
        }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:42: error: 'j' was not declared in this scope
   63 |             REP(i,z) hoge[i] = func(t[i],j);
      |                                          ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

int dep(int n){
    int ret = 0;
    while(n >= 2){
        n /= 2;
        ret++;
    }
    return ret;
}

int memo[pow(2,18)+1][10];


int func(int n,int j){
    if(memo[n][j]) return memo[n][j];
    while(j--) n /= 2;
    return memo[n][j] = n;
}

signed main(){
    //input
    int n; cin >> n;
    int v[n+1],w[n+1];
    REPS(i,n) cin >> v[i] >> w[i];
    int q; cin >> q;
    int M_L = 0;
    int t[q], l[q];
    REP(i,q){
        cin >> t[i] >> l[i];
        chmax(M_L,l[i]);
    }
    //半分全列挙
    int V = min((1ll << 9)-1, n);
    vector<vector<int>> dp(V+1,vector<int>(M_L+1,0));
    REPS(i,V) REP(j,M_L+1){
        chmax(dp[i][j], dp[i/2][j]);
        if(j - w[i] > -1) chmax(dp[i][j], dp[i/2][j-w[i]] + v[i]);
    }
    REP(i,q){
        if(t[i] <= V) cout << dp[t[i]][l[i]] << '\n';
        else{
            int z = dep(t[i]) - 8;
            int ans = 0;
            for(int b = 0; b < (1ll << z); b++){
                int sumw = 0;
                int sumv = 0;
                REP(j,z) if((b >> j) & 1){
                    sumw += w[func(t[i],j)];
                    sumv += v[func(t[i],j)];
                }
                chmax(ans, dp[func(t[i],z)][l[i]-sumw] + sumv);
            }
            cout << ans << '\n';
        }
    }
}

Compiler output:
a.cc:29:19: error: conversion from '__gnu_cxx::__promote<double>::__type' {aka 'double'} to 'long unsigned int' in a converted constant expression
   29 | int memo[pow(2,18)+1][10];
      |          ~~~~~~~~~^~
a.cc:29:19: error: could not convert '(std::pow<int, int>(2, 18) + (__gnu_cxx::__promote<double, false>::__type)1)' from '__gnu_cxx::__promote<double>::__type' {aka 'double'} to 'long unsigned int'
   29 | int memo[pow(2,18)+1][10];
      |          ~~~~~~~~~^~
      |                   |
      |                   __gnu_cxx::__promote<double>::__type {aka double}
a.cc:29:19: error: size of array 'memo' has non-integral type '__gnu_cxx::__promote<double>::__type' {aka 'double'}
Language: C

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 1000000000
using namespace std;

template <typename Value, typename Weight = std::uint_fast64_t> class Knapsack {
public:
	using value_type = Value;
	using weight_type = Weight;
	class item_type {
	public:
		value_type v;
		weight_type w;
		item_type(const value_type &v_, const weight_type &w_) : v(v_), w(w_) {}
		bool operator<(const item_type &x) const {
			if (v * x.w == x.v * w)
				return w > x.w;
			return v * x.w > x.v * w;
		}
	};
	using container_type = std::vector<item_type>;
	using size_type = typename container_type::size_type;

private:
	container_type c;
	value_type best;
	std::pair<double, bool> relaxation(size_type i, value_type v_now,
		weight_type residual) {
		double ret = v_now;
		bool f = 1;
		do {
			if (residual == static_cast<weight_type>(0))
				break;
			if (residual >= c[i].w) {
				residual -= c[i].w;
				v_now += c[i].v;
				ret = v_now;
				continue;
			}
			else {
				f = 0;
				ret += static_cast<double>(c[i].v) *
					(static_cast<double>(residual) / c[i].w);
				break;
			}
		} while (++i < size());
		return std::make_pair(ret, f);
	}
	value_type dfs(size_type i, value_type v_now, weight_type residual) {
		if (i == size()) {
			best = std::max(best, v_now);
			return v_now;
		}
		double relax;
		bool f;
		std::tie(relax, f) = relaxation(i, v_now, residual);
		if (f) {
			best = std::max(best, static_cast<value_type>(relax));
			return static_cast<value_type>(relax);
		}
		if (relax < static_cast<double>(best))
			return 0;
		value_type ret = 0;
		if (residual >= c[i].w)
			ret = std::max(ret, dfs(i + 1, v_now + c[i].v, residual - c[i].w));
		ret = std::max(ret, dfs(i + 1, v_now, residual));
		return ret;
	}

public:
	Knapsack() {}
	bool empty() const { return c.empty(); }
	size_type size() const { return c.size(); }
	template <class... Args> void add(Args &&... args) {
		c.emplace_back(std::forward<Args>(args)...);
	}
	void build() { std::sort(c.begin(), c.end()); }
	value_type solve(const weight_type &capacity) {
		best = 0;
		return dfs(0, 0, capacity);
	}
};

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int N;
    cin >> N;

    int vv[N], ww[N];
    int i, Q;
    for(i = 0; i < N; i++){
        int xx, yy;
        cin >> vv[i] >> ww[i];
    }

    int q;
    cin >> q;

    for(Q = 0; Q < q; Q++){
        int V, W;
        cin >> V >> W;
        vector<int> v, w; //ナップサックされる対象
        Knapsack<int, int> K;
        while(V != 0){
            //cout << V << endl;
            K.add(vv[V-1], ww[V-1]);
            V /= 2;
        }

        K.build();
       cout << K.solve(W) << endl;
    }
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll n;
  std::cin>>n;

  constexpr ll SIZE=1ll<<8
  constexpr ll MAXN=1ll<<18;
  constexpr ll MAXW=100010;

  std::vector<ll> v(MAXN-1,0),w(MAXN-1,0);
  rep(i,0,n)std::cin>>v[i]>>w[i];

  std::vector<std::vector<ll>> dp(SIZE-1,std::vector<ll>(MAXW,0));

  rep(i,w[0],MAXW)dp[0][i]=v[0];

  rep(i,1,SIZE-1){
    rep(j,0,w[i])dp[i][j]=dp[(i-1)/2][j];
    rep(j,w[i],MAXW)dp[i][j]=std::max(dp[(i-1)/2][j],dp[(i-1)/2][j-w[i]]+v[i]);
  }

  ll q;
  std::cin>>q;

  using P=std::pair<ll,ll>;

  while(q--){
    ll a,l;
    std::cin>>a>>l;
    a--;

    if(a<SIZE-1){
      std::cout<<dp[a][l]<<"\n";
      continue;
    }

    std::vector<P> tmp(1,{0,0});
    while(a>=SIZE-1){
      ll m=tmp.size();
      rep(i,0,m){
        if(tmp[i].first+w[a]<=l)tmp.emplace_back(tmp[i].first+w[a],tmp[i].second+v[a]);
      }
      a=(a-1)/2;
    }

    ll ans=0;
    for(const auto& e:tmp){
      chmax(ans,e.second+dp[a][l-e.first]);
    }
    std::cout<<ans<<"\n";
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:92:3: error: expected ',' or ';' before 'constexpr'
   92 |   constexpr ll MAXN=1ll<<18;
      |   ^~~~~~~~~
a.cc:95:21: error: 'MAXN' was not declared in this scope; did you mean 'MAXW'?
   95 |   std::vector<ll> v(MAXN-1,0),w(MAXN-1,0);
      |                     ^~~~
      |                     MAXW
Language: C++

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

typedef long long ll;

ll N;
vector < ll > V, W;
ll Q;
const ll K = 9, L = 100000;
vector < vector < ll >> Dp;
ll I;

ll solve(ll i, ll l) {
    if (i <= I) return Dp[i][l];
    ll res = solve(i / 2, l);
    if (l >= W[i]) 
      res = max(res, V[i] + solve(i / 2, l - W[i]));
    return res;
}
int main() {
    cin >> N;
    V.resize(N + 1);
    W.resize(N + 1);
    for (ll i=1;
         i <= N;
         + +i) cin >> V[i] >> W[i];
    I = min(N, (1ll << K) - 1);
    Dp.resize(I + 1);
    for (auto & dp: Dp) dp.resize(L + 1)
    for (ll i=1;
         i <= I;
         + +i) {
        for (ll l=0;
             l <= L;
             + +l) {
            Dp[i][l] = Dp[i / 2][l];
            if (W[i] <= l)
              Dp[i][l] = max(Dp[i][l], Dp[i / 2][l - W[i]] + V[i]);
        }
    }
    cin >> Q;
    for (ll q=0;
         q < Q;
         + +q) {
        ll i, l;
        cin >> i >> l;
        cout << solve(i, l) << endl;
    }
    return 0
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:41: error: expected ';' before 'for'
   29 |     for (auto & dp: Dp) dp.resize(L + 1)
      |                                         ^
      |                                         ;
   30 |     for (ll i=1;
      |     ~~~                                  
a.cc:31:10: error: 'i' was not declared in this scope
   31 |          i <= I;
      |          ^
a.cc:49:13: error: expected ';' before '}' token
   49 |     return 0
      |             ^
      |             ;
   50 | }
      | ~
Language: C++

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    data = [(0,0)]
    for _ in range(n):
        v,w = map(int,ipt().split())
        data.append((v,w))
    q = int(ipt())
    dp = [[0]*(10**5+1) for _ in range(n+1)]
    dpd = [-1]*(n+1)
    dpd[0] = 1

#dpを先に計算してしまう
    for i in range(1,n+1):
        dpn = dp[i]
        dpp = dp[i//2]
        vi,wi = data[i]
        for j,dpj in enumerate(dpp):
            if j < wi:
                dpn[j] = dpj
            else:
                dpw = dpp[j-wi]
                if dpj < dpw+vi:
                    dpn[j] = dpw+vi
                else:
                    dpn[j] = dpj
        return

    for _ in [0]*q:
        v,l = map(int,ipt().split())
        print(dp[v][l])

    return

if __name__ == '__main__':
    main()


Compiler output:
a.cc:2:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
    2 | #import numpy as np
      |  ^~~~~~
a.cc:2:9: error: #import expects "FILENAME" or <FILENAME>
    2 | #import numpy as np
      |         ^~~~~
a.cc:7:2: error: invalid preprocessing directive #from
    7 | #from scipy.sparse.csgraph import dijkstra
      |  ^~~~
a.cc:8:2: error: invalid preprocessing directive #from
    8 | #from scipy.sparse import csr_matrix
      |  ^~~~
a.cc:23:2: error: invalid preprocessing directive #dp\U00003092\U00005148\U0000306b\U00008a08\U00007b97\U00003057\U00003066\U00003057\U0000307e\U00003046
   23 | #dpを先に計算してしまう
      |  ^~~~~~~~~~~~~~~~~~~~~~
a.cc:45:16: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
   45 | if __name__ == '__main__':
      |                ^~~~~~~~~~
a.cc:1:1: error: 'import' does not name a type
    1 | import math
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

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

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

int main() {
  int N;
  cin >> N;
  
  vector<int> V(N+1), W(N+1);
  rep(i,N) {
    cin >> V.at(i+1) >> W.at(i+1);
  }
  
  int Q;
  cin >> Q;
  
  int v;
  int L;
  rep(q, Q) {
    cin >> v >> L;
    int i = 0;
    vector<vector<int>> dp(N/2+10,vector<int>(L+1, 0));
    while(true){
      for (int sum_w = 0; sum_w <= L; sum_w++) {
        if(sum_w - W.a(v) >= 0) {
          chmax(dp.at(i+1).at(sum_w), dp.at(i).at(sum_w - W.at(v)) + V.at(v));
        }
        chmax(dp.at(i+1).at(sum_w),dp.at(i).at(sum_w));
      }
      i++;
      if((v /= 2 ) < 1) break;
    }
    cout << dp.at(i).at(L) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:22: error: 'class std::vector<int>' has no member named 'a'; did you mean 'at'?
   36 |         if(sum_w - W.a(v) >= 0) {
      |                      ^
      |                      at
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,q;
    short v[262145];
    short w[262145];
    cin>>n;
    int x,y;
    for(int i=1; i<=n; i++)
    {
        cin>>v[i]>>w[i];
    }
    short m[262145][1001]={0};
    for(int i=1;i<=n;i++)
    {
        int r=i/2;
        for(int j=1;j<w[i];j++)
        {
            m[i][j]=m[r][j];
        }
        for(int j=w[i];j<=1000;j++)
        {
            m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]]);
        }
    }
    r[0].push_back(0);
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        cout<<m[x][y]<<'\n';
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:24: error: no matching function for call to 'max(short int&, int)'
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:26:24: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:26:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:29:5: error: 'r' was not declared in this scope
   29 |     r[0].push_back(0);
      |     ^
Language: C++

#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
 
using namespace std;
 
int n;
int q;
int v[1<<18], w[1<<18];
vector<pair<int, int>> dp[1<<18];
 
void solve(int u) {
    if (!dp[u].empty()) {
      return;
    }
    if (dp[u/2].empty()) {
      solve(u/2);
    }
    for (pair<int, int> pii: dp[u/2]) {
      int ww = pii.first;
      int vv = pii.second;
      dp[u].push_back(pii);
      dp[u].push_back({ww + w[u], vv + v[u]});
    }
    sort(dp[u].begin(), dp[u].end());
    for (int i = 1; i < dp[u].size(); i++) {
      if (dp[u][i].second < dp[u][i-1].second) {
        dp[u][i].second = dp[u][i-1].second;
      }
    }
}
 
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &v[i], &w[i]);
  }
  dp[1].push_back({0, 0});
  dp[1].push_back({w[1], v[1]});
  for (int i = 1; i < n && i < (1 << 10); i++) {
    solve(i);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int u, l;
    scanf("%d %d", &u, &l);
    if (u < (1 << 10)) {
      auto it = lower_bound(dp[u].begin(), dp[u].end(), make_pair(l+1, 0));
      printf("%d\n", it - dp[u].begin());
      if (it == dp[u].begin()) {
        printf("0\n");
      } else {
        printf("%d\n", (--it) -> second);
      }
    } else {
      vector<pair<int, int>> brute_force;
      brute_force.push_back({0, 0});
      brute_force.push_back({w[u], v[u]});
      int k = fxxk(u/2, brute_force);
      sort(brute_force.begin(), brute_force.end());
      int l = brute_force.size();
      int p1 = dp[k].size() - 1;
      int p2 = 0;
      int ans = 0;
      while(p2 < l && p1 >= 0) {
        if (dp[k][p1].first + brute_force[p2].first > l) {
          --p1;
        } else {
          ans = max(ans, dp[k][p1].second + brute_force[p2].second);
          ++p2;
        }
      }
      printf("%d\n", ans);
    }
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:15: error: 'fxxk' was not declared in this scope
   60 |       int k = fxxk(u/2, brute_force);
      |               ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define aint(a) (a).begin(),(a).end()
typedef long long int;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(aint(s),x)-s.begin())
#define ub(s,x) (upper_bound(aint(s),x)-s.begin())
#define uniq(a) a.erase(unique(aint(a)),a.end())
#define bit(k) (1int<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int,int>;
#define v first
#define w second

// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}


// O(1000)くらいに収めたい
int knapsack(vector<P> a, int W){
    int N = a.size();
    vector<P> dp = {{0,0}};
    sort(aint(a),comp);

    rep(i,N){
        vector<P> tmp;
        for(P s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }

        sort(aint(tmp),comp);
        dp.clear();
        int w_border = W+1;
        for(P s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
        int SIZE = 32;
        while ((int)dp.size() > SIZE) {
            dp.pop_back();
        }
    }
    // debug(dp.size());
    return dp[0].v;
}


int main(void){
    cin.tie(0); ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n+1),w(n+1);
    rep1(i,n){
        cin >> v[i] >> w[i];
    }
    int Q;
    cin >> Q;
    rep(q,Q){
        int x, L;
        cin >> x >> L;
        vector<P> vp;
        while(x) {
            vp.push_back({v[x], w[x]});
            x /= 2;
        }
        cout << knapsack(vp, L) << endl;
    }
    return 0;
}




Compiler output:
a.cc:5:19: error: declaration does not declare anything [-fpermissive]
    5 | typedef long long int;
      |                   ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
#define N 1000000
#define L 100100

ll M = 512;
vector<vector<ll>> dp(M,vector<ll>(L,0));
vector<ll> val(N);
vector<ll> wei(N);

int main(){
    ll n, v, l, q; cin >> n;
    REP(i,n) cin >> val[i+1] >> wei[i+1];
    cin >> q;
    FOR(i,1,min(M-1,n)){
        REP(j,L){
            if (j-wei[i]>=0) dp[i][j]=max(dp[i/2][j],dp[i/2][j-wei[i]]+val[i]);
            else dp[i][j]=dp[i/2][j];
        }
    }
    vector<vector<vector<ll>>> fvall(M);
    REP(i,M){
        REP(j,L){
            if (dp[i][j]!=0) {
                if (j>=1) dp[i][j]=max(dp[i][j-1],dp[i][j]);
                fvall[i].pb({j,dp[i][j]});
            }
            else{
                if (j>=1) dp[i][j]=max(dp[i][j-1],dp[i][j]);
            }
        }
    }
    REP(i,fvall.size()) sort(fvall[i].begin(),fvall[i].end());
    REP(i,q){
        cin >> v >> l;
        if (v<M){
            ll ans = 0;
            REP(j,vall[v].size()) if (vall[v][j][0]<=l) ans = max(ans,vall[v][j][1]);
            cout << ans << endl;
        }
        else{
            ll ans = 0;
            vector<ll> jelv;
            vector<ll> jelw;
            while(v>=M){
                jelv.pb(val[v]);
                jelw.pb(wei[v]);
                v/=2;
            }
            vector<ll> lval;
            vector<ll> li;
            REP(i,fvall[v].size()) li.pb(fvall[v][i][0]);
            ll len = jelv.size();
            REP(j,(1ll<<len)){
                ll twei = 0; ll tval = 0;
                REP(p,len){
                    if ((j>>p)%2){
                        tval+=jelv[p];
                        twei+=jelw[p];
                    }
                }
                ll ind = upper_bound(li.begin(),li.end(),l-twei)-li.begin();
                if (ind-1>=0){
                    ans=max(ans,tval+fvall[v][ind-1][1]);
                }
            }
            cout << ans << endl;
        }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:19: error: 'vall' was not declared in this scope; did you mean 'fvall'?
   50 |             REP(j,vall[v].size()) if (vall[v][j][0]<=l) ans = max(ans,vall[v][j][1]);
      |                   ^~~~
a.cc:5:39: note: in definition of macro 'REP'
    5 | #define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
      |                                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,q;
    short v[262145];
    short w[262145];
    cin>>n;
    int x,y;
    for(int i=1; i<=n; i++)
    {
        cin>>v[i]>>w[i];
    }
    short m[262145][1001]={0};
    for(int i=1;i<=n;i++)
    {
        int r=i/2;
        for(int j=1;j<w[i];j++)
        {
            m[i][j]=m[r][j];
        }
        for(int j=w[i];j<=1000;j++)
        {
            m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]);
        }
    }
    r[0].push_back(0);
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        cout<<m[x][y]<<'\n';
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:49: error: expected ']' before ')' token
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]);
      |                                                 ^
      |                                                 ]
a.cc:26:24: error: no matching function for call to 'max(short int&, int)'
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:26:24: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:26:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   26 |             m[i][j]=max(m[r][j],v[i]+m[r][j-w[i]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:29:5: error: 'r' was not declared in this scope
   29 |     r[0].push_back(0);
      |     ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e7;

int main() {
    int n; cin >> n;
    vector<P> data(n);
    rep(i,n) {
        int v, w; cin >> v >> w;
        data[i] = P(v,w);
    }
    map<int,vector<int>> mp;
    mp[0] = vint(mx,0);
    REP(i,n+1) {
        vint x = mp[i/2];
        rep(j,mx) {
            if (j-data[i].second >= 0) {
                (x[j],x[j-data[i].second]+data[i].first);
            }
        }
        mp[i] = x;
    }
    int q; cin >> q;
    rep(i,q) {
        int v, l; cin >> v >> l;
        cout << mp[v][l] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:18: error: 'mx' was not declared in this scope; did you mean 'mp'?
   28 |     mp[0] = vint(mx,0);
      |                  ^~
      |                  mp
a.cc:33:21: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   33 |                 (x[j],x[j-data[i].second]+data[i].first);
      |                     ^
In file included from /usr/include/c++/14/vector:66,
                 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/stl_vector.h:1128:7: note: declared here
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
Language: C++

15
123 119
129 120
132 112
126 109
118 103
115 109
102 100
130 120
105 105
132 115
104 102
107 107
127 116
121 104
121 115
8
8 234
9 244
10 226
11 227
12 240
13 237
14 206
15 227

Compiler output:
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 15
      | ^~
Language: C++

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int n;
vector<vector<ll>> dp(1, vector<ll>(100001, 0));
vector<ll> ans;
vector<ll> v, w;
vector<ll> query;
void solve(int now) {
    if(now > n) {
        return;
    }
    dp.push_back(vector<ll>(100001, 0));
    int m = dp.size() - 1;
    for(int j = 0; j <= 100000; j++) {
        dp[m][j] = dp[m - 1][j];
        if(j - w[now] >= 0) {
            dp[m][j] = max(dp[m - 1][j], dp[m - 1][j - w[now]] + v[now]);
        }
    }
    if(query[now] != -1) {
        for(int i = 0; i <= query[now]; i++) {
            ans[now] = max(ans[now], dp[m][i]);
        }
    }
    solve(now * 2, now);
    solve(now * 2 + 1, now);
    dp.pop_back();
}
int main() {
    cin >> n;
    v.resize(n + 1, 0);
    w.resize(n + 1, 0);
    for(int i = 0; i < n; i++) {
        cin >> v[i + 1] >> w[i + 1];
    }
    int q;
    cin >> q;
    query.resize(n + 1, -1);
    ans.resize(n + 1, 0);
    vector<ll> ans_ind;
    for(int i = 0; i < q; i++) {
        ll u, l;
        cin >> u >> l;
        query[u] = l;
        ans_ind.push_back(u);
    }
    solve(1);
    for(auto e : ans_ind) {
        cout << ans[e] << endl;
    }
}

Compiler output:
a.cc: In function 'void solve(int)':
a.cc:28:10: error: too many arguments to function 'void solve(int)'
   28 |     solve(now * 2, now);
      |     ~~~~~^~~~~~~~~~~~~~
a.cc:11:6: note: declared here
   11 | void solve(int now) {
      |      ^~~~~
a.cc:29:10: error: too many arguments to function 'void solve(int)'
   29 |     solve(now * 2 + 1, now);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:11:6: note: declared here
   11 | void solve(int now) {
      |      ^~~~~
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;

int arr[(1<<18) + 1];
int n,q;
int v[(1<<18) + 1],w[(1<<18) + 1];
int dp[20000][50000];
int inf = -100;
int vq,wq;

int dfs(int i, int weight){
    //cout << i << " " << weight << " " << dp[i][weight] << endl;
    int res=0;
    if(i < 20000 && weight < 50000){
        if(dp[i][weight] != inf) return dp[i][weight];
    }
    if(i == 0){
        res = 0;
    }
    else if(weight < w[i] ){
        res = dfs(i/2,weight);
    }
    else{
        res = max(dfs(i/2,weight),dfs(i/2,weight-w[i])+v[i]);
    }
    if (i < 20000 && weight < 50000) dp[i][weight] = res;
    return res;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> v[i] >> w[i] ;
    }
    for(int i=0;i<20000;i++){
        for(int j=0;j<=50000;j++){
            dp[i][j] = inf;
        }
    }
    
    cin >> q;
    for(int j=0;j<q;j++){
        cin >> vq >> wq;
        cout << dfs(vq,wq) << endl;
    
    }
    return 0;
}

Compiler output:
/tmp/ccpvj4b7.o: in function `main':
a.cc:(.text+0x29e): relocation truncated to fit: R_X86_64_PC32 against symbol `vq' defined in .bss section in /tmp/ccpvj4b7.o
a.cc:(.text+0x2ba): relocation truncated to fit: R_X86_64_PC32 against symbol `wq' defined in .bss section in /tmp/ccpvj4b7.o
a.cc:(.text+0x2cb): relocation truncated to fit: R_X86_64_PC32 against symbol `wq' defined in .bss section in /tmp/ccpvj4b7.o
a.cc:(.text+0x2d1): relocation truncated to fit: R_X86_64_PC32 against symbol `vq' defined in .bss section in /tmp/ccpvj4b7.o
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;

int arr[(1<<18) + 1];
int n,q;
int v[(1<<18) + 1],w[(1<<18) + 1];
int dp[20000][50000];
int inf = -100;
int vq,wq;

int dfs(int i, int weight){
    //cout << i << " " << weight << " " << dp[i][weight] << endl;
    int res=0;
    if(i < 200 && weight < 50000){
        if(dp[i][weight] != inf) return dp[i][weight];
    }
    if(i == 0){
        res = 0;
    }
    else if(weight < w[i] ){
        res = dfs(i/2,weight);
    }
    else{
        res = max(dfs(i/2,weight),dfs(i/2,weight-w[i])+v[i]);
    }
    if (i < 200 && weight < 50000) dp[i][weight] = res;
    return res;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> v[i] >> w[i] ;
    }
    for(int i=0;i<200;i++){
        for(int j=0;j<=50000;j++){
            dp[i][j] = inf;
        }
    }
    
    cin >> q;
    for(int j=0;j<q;j++){
        cin >> vq >> wq;
        cout << dfs(vq,wq) << endl;
    
    }
    return 0;
}

Compiler output:
/tmp/cch8SW7q.o: in function `main':
a.cc:(.text+0x29e): relocation truncated to fit: R_X86_64_PC32 against symbol `vq' defined in .bss section in /tmp/cch8SW7q.o
a.cc:(.text+0x2ba): relocation truncated to fit: R_X86_64_PC32 against symbol `wq' defined in .bss section in /tmp/cch8SW7q.o
a.cc:(.text+0x2cb): relocation truncated to fit: R_X86_64_PC32 against symbol `wq' defined in .bss section in /tmp/cch8SW7q.o
a.cc:(.text+0x2d1): relocation truncated to fit: R_X86_64_PC32 against symbol `vq' defined in .bss section in /tmp/cch8SW7q.o
collect2: error: ld returned 1 exit status
Language: C++

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

int N, Q;
vector<ll> V, W, v, L;
vector<vector<int>> query;
vector<map<int, ll>> vmp;

void dfs(int now) {
    if (now > N) return;
    if (now*2 > N && query[now].empty()) return; 
    if (now == 1) {
        vmp[1][0] = 0;
        vmp[1][W[1]] = V[1];
    }else if (now <= 4095 || now >= 8192) {
        for (auto p : vmp[now/2]) {
            //cout << now << " " << p.first << " " << p.second << endl;
            vmp[now][p.first] = max(vmp[now][p.first], p.second);
            if (p.first + W[now] <= 100000) {
                //cout << now << " " << p.first+W[now] << " " << p.second+V[now] << endl;
                //cout << now << " " << W[now] << " " << V[now] << endl;
                vmp[now][p.first+W[now]] = max(vmp[now][p.first+W[now]], p.second+V[now]);
            }
        }
    }else {
        vmp[now][0] = 0;
        vmp[now][W[now]] = V[now];
    }
    if (now <= 4095) {
        auto it = vmp[now].begin();
        ll v_max = 0;
        it++;
    
        while (it != vmp[now].end()) {
            v_max = max(v_max, (*it).second);
            (*it).second = max((*it).second, v_max);
            it++;
        }
    }
    
    dfs(now*2);
    dfs(now*2+1);
    
    return;
}

int main() {
    cin >> N;
    V.resize(N+1, 0);
    W.resize(N+1, 0);
    for (int i = 1; i <= N; i++) cin >> V[i] >> W[i];
    cin >> Q;
    v.resize(Q);
    L.resize(Q);
    ans.resize(Q);
    query.resize(N+1);
    vmp.resize(N+1);
    for (int i = 0; i < Q; i++) {
        cin >> v[i] >> L[i];
        query[v[i]].push_back(i);
    }
    
    dfs(1);
    for (int i = 0; i < Q; i++) {
        if (v[i] <= 4095) {
            auto it = vmp[v[i]].lower_bound(L[i]);
            if ((*it).first > L[i]) it--;
            cout << (*it).second << "\n";
        }else {
            ll ans = 0;
            ll par = v[i];
            ll v_max = 0;
            while (par >= 4096) par /= 2;
            auto it = vmp[v[i]].begin();
            auto it2 = vmp[par].lower_bound(L[i]-(*it).first);
            while (it != vmp[v[i]].end() && (*it).first <= L[i]) {
                v_max = max(v_max, (*it).second);
                
                while (it2 != vmp[par].begin() && (*it2).first > L[i]-(*it).first) it2--;
                ans = max(ans, (*it).second + v_max);
                it++;
            }
            cout << ans << "\n";
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   56 |     ans.resize(Q);
      |     ^~~
      |     abs
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define aint(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(aint(x)), x.end());
typedef long long int;
typedef complex<double> Complex;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
void calc(vector<int> v, vector<int> w, vector<pair<int, int>>& ret) {
    int n = v.size();
    ret.resize(1 << n);
    rep(i, 1 << n) {
        int vv = 0, ww = 0;
        rep(j, n) {
            if ((i >> j) & 1) {
                vv += v[j];
                ww += w[j];
            }
        }
        ret[i] = (make_pair(ww, vv));
    }
    sort(aint(ret));
}
int main() {
    int nn;
    cin >> nn;
    vector<int> vv(nn + 1), ww(nn + 1);
    rep(i, nn) cin >> vv[i + 1] >> ww[i + 1];
    int q;
    cin >> q;
    vector<int> v, w, v1, w1, v2, w2;
    vector<pair<int, int>> p1, p2;
    while (q--) {
        v.clear();
        w.clear();
        v1.clear();
        w1.clear();
        v2.clear();
        w2.clear();
        p1.clear();
        p2.clear();
        int now, l;
        cin >> now >> l;
        while (now) {
            v.push_back(vv[now]);
            w.push_back(ww[now]);
            now >>= 1;
        }
        int n = sz(v);
        rep(i, n) {
            if (i & 1) {
                v1.push_back(v[i]);
                w1.push_back(w[i]);
            } else {
                v2.push_back(v[i]);
                w2.push_back(w[i]);
            }
        }
        calc(v1, w1, p1);
        calc(v2, w2, p2);
        n = p1.size();
        int m = p2.size();
        int ans = 0, ma = 0;
        int j = 0;
        FORR(i, n - 1, 0) {
            if (p1[i].first > l) continue;
            while (j < m && p1[i].first + p2[j].first <= l) {
                ma = max(ma, p2[j].second);
                j++;
            }
            ans = max(ans, p1[i].second + ma);
        }
        cout << ans << '\n';
    }
}

Compiler output:
a.cc:9:19: error: declaration does not declare anything [-fpermissive]
    9 | typedef long long int;
      |                   ^~~
a.cc:13:18: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   13 | const int LINF = 1e18;
      |                  ^~~~