Language: C++

#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;
const int size=4000;
int amount;
vector<vector<int>> tree(size, vector<int>(1));
vector<tuple<int, int, int>> values(size);
vector<tuple<int, int>> weights(size);
vector<tuple<int, int, int>> selectedValues(size);
vector<int> sumValues(size);
void fillingValues()
{
	int pointValue, pointWeight;
	cin>>amount;
	//Changing all parameters-vector's sizes to 0.
	values.resize(0);
	weights.resize(0);
	selectedValues.resize(0);
	sumValues.resize(0);
	for(int point=1; point<=amount; ++point)
	{
		cin>>pointValue>>pointWeight;
		values.push_back(make_tuple(point, pointValue, pointWeight));
	}
	return;
}
void fillingWeights()
{
	int borderPoint, borderWeight, queryNumbers;
	cin>>queryNumbers;
	for(int i=1; i<=queryNumbers; ++i)
	{
		cin>>borderPoint>>borderWeight;
		weights.push_back(make_tuple(borderPoint, borderWeight));
	}
	return;
}
/*
void creatingTree(int root)
{
	if(root>amount)
	{
		return;
	}
	tree[root].push_back(2*root);
	tree[root].push_back(2*root+1);
	tree[2*root].push_back(root);
	tree[2*root+1].push_back(root);
	creatingTree(2*root);
	creatingTree(2*root+1);
	return;
}
*/
void dfs(int root, int borderWeight)
{
	if(root==0)
	{
		for(int i=0; i<selectedValues.size()-1; ++i)
		{
			for(int j=(i+1); j<selectedValues.size(); ++j)
			{
				if((get<2>(selectedValues[i])+get<2>(selectedValues[j]))<=borderWeight)
				{
					sumValues.push_back((get<1>(selectedValues[i])+get<1>(selectedValues[j])));
				}
			}
		}
		cout<<*max_element(sumValues.begin(), sumValues.end())<<endl;
		return;
	}
	for(int i=0; i<values.size(); ++i)
	{
		if(get<0>(values[i])==root)
		{
			selectedValues.push_back(values[i]);
		}
	}
	dfs(root/2, borderWeight);
	return;
}
void usingDfs()
{
	for(int i=0; i<weights.size(); ++i)
	{
		dfs(get<0>(weights[i]), get<1>(weights[i]));
		sumValues.clear();
		selectedValues.clear();
	}
	return;
}
int main()
{
	fillingValues();
	fillingWeights();
	creatingTree(1);
	usingDfs();
	return 0;
}

Compiler output:
a.cc:8:26: error: reference to 'size' is ambiguous
    8 | vector<vector<int>> tree(size, vector<int>(1));
      |                          ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:11: note:                 'const int size'
    6 | const int size=4000;
      |           ^~~~
a.cc:9:37: error: reference to 'size' is ambiguous
    9 | vector<tuple<int, int, int>> values(size);
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:11: note:                 'const int size'
    6 | const int size=4000;
      |           ^~~~
a.cc:10:33: error: reference to 'size' is ambiguous
   10 | vector<tuple<int, int>> weights(size);
      |                                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:11: note:                 'const int size'
    6 | const int size=4000;
      |           ^~~~
a.cc:11:45: error: reference to 'size' is ambiguous
   11 | vector<tuple<int, int, int>> selectedValues(size);
      |                                             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:11: note:                 'const int size'
    6 | const int size=4000;
      |           ^~~~
a.cc:12:23: error: reference to 'size' is ambiguous
   12 | vector<int> sumValues(size);
      |                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:11: note:                 'const int size'
    6 | const int size=4000;
      |           ^~~~
a.cc: In function 'int main()':
a.cc:97:9: error: 'creatingTree' was not declared in this scope
   97 |         creatingTree(1);
      |         ^~~~~~~~~~~~