Language: C++

//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
int dp[1024][100005];
void solve()
{
    ll n;
    cin>>n;
    ll wt[n+1];
    ll val[n+1];
    for(int i=1;i<=n;i++)
        cin>>val[i]>>wt[i];
    ll q;
    cin>>q;
    for(int i=1;i<min(n+1,1024);i++)
    {
        if(i==1)
        {
            for(int j=wt[i];j<=100000;j++)
                dp[i][j]=val[i];
            continue;
        }
        int par=i/2;
        for(int j=1;j<=100000;j++)
        {
            if(wt[i]>j)
                dp[i][j]=dp[par][j];
            else
                dp[i][j]=max(dp[par][j],dp[par][j-wt[i]]+val[i]);
        }
    }
    while(q--)
    {
        int v,W;
        cin>>v>>W;
        if(v<1024)
        {
            cout<<dp[v][W]<<'\n';
            continue;
        }
        vi anc;
        while(v>=1024)
        {
            anc.pb(v);
            v/=2;
        }
        int res=anc.size();
        int ans=0;
        for(int i=0;i<(1<<res);i++)
        {
            int sumval=0,sumwt=0;
            for(int j=0;j<res;j++)
            {
                if((i&j)!=0)
                {
                    sumval+=val[anc[j]];
                    sumwt+=wt[anc[j]];
                }
            }
            if(sumwt>W)
                continue;
            ans=max(ans,sumval+dp[v][W-sumwt]);
        }
        cout<<ans<<'\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:42:22: error: no matching function for call to 'min(long long int, int)'
   42 |     for(int i=1;i<min(n+1,1024);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: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:42:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |     for(int i=1;i<min(n+1,1024);i++)
      |                   ~~~^~~~~~~~~~
/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:42:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |     for(int i=1;i<min(n+1,1024);i++)
      |                   ~~~^~~~~~~~~~
a.cc:56:29: error: no matching function for call to 'max(int&, long long int)'
   56 |                 dp[i][j]=max(dp[par][j],dp[par][j-wt[i]]+val[i]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:56:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   56 |                 dp[i][j]=max(dp[par][j],dp[par][j-wt[i]]+val[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
/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:56:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   56 |                 dp[i][j]=max(dp[par][j],dp[par][j-wt[i]]+val[i]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~