Language: C++

#ifndef ___Class_RMQ
#define ___Class_RMQ

#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

template <typename Type> class RMQ
{
private:

	int size;

	vector<Type> maxvalue;

	Type _query(int a, int b, int k, int l, int r)
	{
		if (r <= a || b <= l) { return -INF; }
		if (a <= l && r <= b) { return maxvalue[k]; }

		Type vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
		Type vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);

		return max(vl, vr);
	}

public:

	Type INF;

	RMQ(int size_)
	{
		INF = numeric_limits<Type>::max();

		for (size = 1; size < size_;) { size <<= 1; }

		maxvalue = vector<Type>(size * 2 - 1, -INF);
	}

	void update(int i, const Type& x)
	{
		i += size - 1;

		maxvalue[i] = x;

		while (i > 0)
		{
			i = (i - 1) / 2;

			maxvalue[i] = max(maxvalue[2 * i + 1], maxvalue[2 * i + 2]);
		}
	}

	Type query(int s, int t)
	{
		return _query(s, t, 0, 0, size);
	}
};

#endif


#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int power[16]; power[0] = 1;

	for (int i = 1; i < 16; i++)
	{
		power[i] = power[i - 1] * 3;
	}

	int N; long long D;

	cin >> N >> D;

	int mid = N / 2;

	vector<long long> X(N);
	vector<long long> Y(N);

	for (int i = 0; i < N; i++)
	{
		cin >> X[i] >> Y[i];
	}

	vector<pair<long long, long long> > D1, D2;

	for (int i = 0; i < power[mid]; i++)
	{
		long long X3 = 0LL, Y3 = 0LL;

		for (int j = 0; j < mid; j++)
		{
			switch ((i / power[j]) % 3)
			{
			case 0: X3 -= X[j]; Y3 -= Y[j]; break; // Anna
			case 1: X3 += X[j]; Y3 += Y[j]; break; // Bruno
			}
		}

		D1.push_back(make_pair(X3, Y3));
	}

	for (int i = 0; i < power[N - mid]; i++)
	{
		long long X3 = 0LL, Y3 = 0LL;

		for (int j = mid; j < N; j++)
		{
			switch ((i / power[j - mid]) % 3)
			{
			case 0: X3 -= X[j]; Y3 -= Y[j]; break; // Anna
			case 1: X3 += X[j]; Y3 += Y[j]; break; // Bruno
			}
		}

		D2.push_back(make_pair(X3, Y3));
	}

	sort(D2.begin(), D2.end(), [](pair<long long, long long> x, pair<long long, long long> y) { return x.first < y.first; });

	vector<long long> X1;

	RMQ<long long> Y1(D2.size());

	for (int i = 0; i < D2.size(); i++)
	{
		X1.push_back(D2[i].first);

		Y1.update(i, D2[i].second);
	}

	long long Ans = -(1LL << 60), rmq;

	int ptr1, ptr2;

	for (int i = 0; i < D1.size(); i++)
	{
		ptr1 = distance(X1.begin(), lower_bound(X1.begin(), X1.end(), -D1[i].first - D));
		ptr2 = distance(X1.begin(), upper_bound(X1.begin(), X1.end(), -D1[i].first + D));

		rmq = Y1.query(ptr1, ptr2);

		if (rmq != -Y1.INF)
		{
			Ans = max(D1[i].second + rmq, Ans);
		}
	}

	cout << Ans << endl;

	return 0;
}

Compiler output:
a.cc: In constructor 'RMQ<Type>::RMQ(int)':
a.cc:35:23: error: 'numeric_limits' was not declared in this scope
   35 |                 INF = numeric_limits<Type>::max();
      |                       ^~~~~~~~~~~~~~
a.cc:35:42: error: expected primary-expression before '>' token
   35 |                 INF = numeric_limits<Type>::max();
      |                                          ^
a.cc:35:48: error: no matching function for call to 'max()'
   35 |                 INF = numeric_limits<Type>::max();
      |                                           ~~~~~^~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:4:
/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:   candidate expects 2 arguments, 0 provided
/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, 0 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:6:
/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, 0 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:   candidate expects 2 arguments, 0 provided