Language: C++

#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int N, d;
	cin>>N>>d;
	vector<P(ll, P)> h(N);
	priority_queue<ll> q;
	set<ll> s;
	REP(i, N) {
		ll x, y, b;
		cin>>x>>y>>b;
		h[i].first = b;
		h[i].second.first = x;
		h[i].second.second = y;
		if(!s.count(b)) {
			s.insert(b);
			q.push(b);
		}
	}
	sort(ALL(h));
	ll ite = 0;
	ll ans = 0;
	priority_queue<P> ux;
	priority_queue<P> lx;
	priority_queue<P> uy;
	priority_queue<P> ly;
	REP(i, q.size()) {
		ll lbr = q.top();
		q.pop();
		while(h[ite].first <= lbr + d) {
			ux.push(P(h[ite].second.first, h[ite].first));
			lx.push(P(-(h[ite].second.first), h[ite].first));
			uy.push(P(h[ite].second.second, h[ite].first));
			ly.push(P(-(h[ite].second.second), h[ite].first));
			++ite;
		}
		ll maxx = -1, maxy = -1, minx = -1, miny = -1;

		while(!ux.empty()) {
			P hoge = ux.top();
			if(hoge.second >= lbr && hoge.second <= lbr + d) {
				maxx = hoge.first;
				break;
			} else {
				ux.pop();
			}
		} while(!lx.empty()) {
			P hoge = lx.top();
			if(hoge.second >= lbr && hoge.second <= lbr + d) {
				minx = -(hoge.first);
				break;
			} else {
				lx.pop();
			}
		} while(!uy.empty()) {
			P hoge = uy.top();
			if(hoge.second >= lbr && hoge.second <= lbr + d) {
				maxy = hoge.first;
				break;
			} else {
				uy.pop();
			}
		} while(!ly.empty()) {
			P hoge = ux.top();
			if(hoge.second >= lbr && hoge.second <= lbr + d) {
				miny = -(hoge.first);
				break;
			} else {
				ly.pop();
			}
		}
		ans = max(ans, (maxx - minx) * (maxy - miny));
	}
	cout<<ans<<endl;
}

Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 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/new_allocator.h: In instantiation of 'class std::__new_allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>':
/usr/include/c++/14/bits/allocator.h:128:11:   required from 'class std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>'
  128 |     class allocator : public __allocator_base<_Tp>
      |           ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:87:21:   required from 'struct std::_Vector_base<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>), std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)> >'
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:33:22:   required from here
   33 |         vector<P(ll, P)> h(N);
      |                             ^
/usr/include/c++/14/bits/new_allocator.h:111:7: error: 'const _Tp* std::__new_allocator<_Tp>::address(const_reference) const [with _Tp = std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>); const_pointer = std::pair<long long int, long long int> (*)(long long int, std::pair<long long int, long long int>); const_reference = std::pair<long long int, long long int> (&)(long long int, std::pair<long long int, long long int>)]' cannot be overloaded with '_Tp* std::__new_allocator<_Tp>::address(reference) const [with _Tp = std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>); pointer = std::pair<long long int, long long int> (*)(long long int, std::pair<long long int, long long int>); reference = std::pair<long long int, long long int> (&)(long long int, std::pair<long long int, long long int>)]'
  111 |       address(const_reference __x) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~
/usr/include/c++/14/bits/new_allocator.h:107:7: note: previous declaration '_Tp* std::__new_allocator<_Tp>::address(reference) const [with _Tp = std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>); pointer = std::pair<long long int, long long int> (*)(long long int, std::pair<long long int, long long int>); reference = std::pair<long long int, long long int> (&)(long long int, std::pair<long long int, long long int>)]'
  107 |       address(reference __x) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~
a.cc: In function 'int main()':
a.cc:39:22: error: request for member 'first' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   39 |                 h[i].first = b;
      |                      ^~~~~
a.cc:40:22: error: request for member 'second' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   40 |                 h[i].second.first = x;
      |                      ^~~~~~
a.cc:41:22: error: request for member 'second' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   41 |                 h[i].second.second = y;
      |                      ^~~~~~
a.cc:57:30: error: request for member 'first' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)ite))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   57 |                 while(h[ite].first <= lbr + d) {
      |                              ^~~~~
a.cc:58:42: error: request for member 'second' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)ite))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   58 |                         ux.push(P(h[ite].second.first, h[ite].first));
      |                                          ^~~~~~
a.cc:58:63: error: request for member 'first' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)ite))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   58 |                         ux.push(P(h[ite].second.first, h[ite].first));
      |                                                               ^~~~~
a.cc:59:44: error: request for member 'second' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)ite))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   59 |                         lx.push(P(-(h[ite].second.first), h[ite].first));
      |                                            ^~~~~~
a.cc:59:66: error: request for member 'first' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)ite))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::value_type' {aka 'std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)'}
   59 |                         lx.push(P(-(h[ite].second.first), h[ite].first));
      |                                                                  ^~~~~
a.cc:60:42: error: request for member 'second' in 'h.std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::operator[](((std::vector<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>::size_type)ite))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int>(long long int, std::pair<long long int, long long int>)>, std::pair<long long int, long long int>(long long int,