Language: C++

//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

vector<vector<ll>> comb(ll n, ll k) {
	if (n == 0) return {};
	if (k == 0) return {};
	if (n < k) return {};

	vector<vector<ll>> res;
	if (k == 1) {
		for (ll i = 0; i < n; ++i) {
			res.emplace_back(vector<ll>(1, i));
		}
		return res;
	}
	if (n == k) {
		vector<ll> v(n);
		for (ll i = 0; i < n; ++i) {
			v[i] = i;
		}
		res.emplace_back(v);
		return res;
	}
	res = comb(n - 1, k);
	vector<vector<ll>> pre = comb(n - 1, k - 1);
	res.reserve(res.size() + pre.size());
	for (ll i = 0; i < pre.size(); ++i) {
		pre[i].emplace_back(n - 1);
	}
	copy(pre.begin(), pre.end(), std::back_inserter(res));

	return res;
}

int solve() {
	ll n;
	cin >> n;

	ll x, y, p;
	vector<tuple<ll, ll, ll>> xyps(n);
	REPD(i, 0, n) {
		cin >> x >> y >> p;
		xyps[i] = { x, y, p };
	}

	REPD(k, 0, n + 1) {
		ll res = LLONG_MAX;

		REPD(row_count, 0, k + 1) {
			ll col_count = k - row_count;
			auto row_combs = comb(n, row_count);
			auto col_combs = comb(n, col_count);
			row_combs.emplace_back(vector<ll>());
			col_combs.emplace_back(vector<ll>());
			REPI(row_comb, row_combs) {
				REPI(col_comb, col_combs) {
					vector<ll> rows(row_count + 1);
					vector<ll> cols(col_count + 1);
					REPD(i, 0, row_comb.size()) {
						rows[i] = get<1>(xyps[row_comb[i]]);
					}
					REPD(i, 0, col_comb.size()) {
						cols[i] = get<0>(xyps[col_comb[i]]);
					}
					sort(rows.begin(), rows.end());
					sort(cols.begin(), cols.end());

					ll curr_val = 0;
					REPD(i, 0, n) {
						tie(x, y, p) = xyps[i];
						ll dist = LLONG_MAX;
						REPD(jx, 0, cols.size()) {
							dist = min(dist, abs(cols[jx] - x));
						}
						REPD(jy, 0, rows.size()) {
							dist = min(dist, abs(rows[jy] - y));
						}
						curr_val += dist * p;
					}
					res = min(res, curr_val);
				}

			}
		}

		cout << res << endl;
	}

	return 0;
}

//main function
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:101:26: error: 'LLONG_MAX' was not declared in this scope
  101 |                 ll res = LLONG_MAX;
      |                          ^~~~~~~~~
a.cc:29:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   28 | #include <ctime>
  +++ |+#include <climits>
   29 |