Language: C++

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jul 25 22:14:29 JST 2020
 **/

template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> x(n), y(n), p(n);
    REP(i, n) std::cin >> x[i] >> y[i] >> p[i];
    std::vector<int> x_ord(n), y_ord(n);
    std::iota(ALL(x_ord), 0);
    std::sort(ALL(x_ord), [&](Int i, Int j) { return x[i] < x[j]; });
    std::iota(ALL(y_ord), 0);
    std::sort(ALL(y_ord), [&](Int i, Int j) { return y[i] < y[j]; });
    std::vector<int> x_ord_rev = {x_ord.rbegin(), x_ord.rend()}, y_ord_rev = {y_ord.rbegin(), y_ord.rend()};
    std::vector<Int> orig_dist(n), min_dist(n);
    REP(i, n) orig_dist[i] = std::min(std::abs(x[i]), std::abs(y[i]));
    std::vector<Int> ans(n + 1, 1e18);
    REP(S, 1 << n) {
        // Sの部分集合の列挙
        for (int T = S;; T = (T - 1) & S) {
            // 操作
            REP(i, n) min_dist[i] = orig_dist[i];
            for (auto& xv : {x_ord, x_ord_rev}) {
                Int l = -1e9;
                for (Int i : xv) {
                    if (T >> i & 1) l = x[i];
                    chmin(min_dist[i], std::abs(x[i] - l));
                }
            }
            for (auto& yv : {y_ord, y_ord_rev}) {
                Int l = -1e9;
                for (Int i : yv) {
                    if ((S ^ T) >> i & 1) l = y[i];
                    chmin(min_dist[i], std::abs(y[i] - l));
                }
            }
            Int acc = 0;
            REP(i, n) acc += p[i] * min_dist[i];
            chmin(ans[__builtin_popcount(S)], acc);
            if (T == 0) break;
        }
    }
    for (Int z : ans) std::cout << z << "\n";
}


Compiler output:
In file included 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:4:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<long long int, std::allocator<long long int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long long int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~