Language: C++

#include<vector>
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, l, (l + r) / 2);
		Type vr = _query(a, b, 2 * k + 1, (l + r) / 2, r);

		return max(vl, vr);
	}

public:

	Type INF;

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

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

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

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

		maxvalue[i] = x;

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

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

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

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<utility>

#define MAX_N 20000000

long long x_1[MAX_N];
long long y_1[MAX_N];
pair<long long, long long>x2[MAX_N];
long long y2[MAX_N];
RMQ<long long> r(14348907);

int main() {
	long long x[15][2], y[15][2], d;
	int power[16] = { 1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907 };
	int n, e, f;
	int mid;
	long long int MAX = 0;
	int a[15];

	memset(x_1, 0, sizeof(x_1));
	memset(y_1, 0, sizeof(y_1));

	cin >> n >> d;
	mid = n / 2;

	for (int i = 0; i < mid; i++) {
		cin >> x[i][0] >> y[i][0];
	}
	for (int i = mid; i < n; i++) {
		cin >> x[i - mid][1] >> y[i - mid][1];
	}

	for (int i = 0; i < power[mid]; i++) {
		for (int j = 0; j < mid; j++) {
			a[j] = (i / power[j]) % 3;
			if (a[j] == 0) {
				x_1[i] -= x[j][0];
				y_1[i] -= y[j][0];
			}
			if (a[j] == 1) {
				x_1[i] += x[j][0];
				y_1[i] += y[j][0];
			}
		}
	}

	for (int i = 0; i < power[n - mid]; i++) {
		for (int j = 0; j < n - mid; j++) {
			a[j] = (i / power[j]) % 3;
			if (a[j] == 0) {
				x2[i].first -= x[j][1];
				x2[i].second -= y[j][1];
			}
			if (a[j] == 1) {
				x2[i].first += x[j][1];
				x2[i].second += y[j][1];
			}
		}
	}

	sort(x2, x2 + power[n - mid]);

	for (int i = 0; i < power[n - mid]; i++) {
		y2[i] = x2[i].first;
		r.update(i, x2[i].second);
	}

	for (int i = 0; i < power[mid]; i++) {
		e = distance(y2, lower_bound(y2, y2 + power[n - mid], -x_1[i] - d));
		f = distance(y2, upper_bound(y2, y2 + power[n - mid], -x_1[i] + d));
		MAX = max(MAX, r.query(e, f) + y_1[i]);
	}

	cout << MAX << endl;

	return 0;
}

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