Language: C++

#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
#define pb push_back
#define IT iterator
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=17,size=1<<20,mod=998244353,inf=2e9;

char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

//math
ll mult(ll a,ll b,ll p) {
	a=(a%p+p)%p; b=(b%p+p)%p;
	ll c=(ld)a*b/p;
	return a*b-c*p;
}
ll gcd(ll a,ll b) {return !a?b:gcd(b%a,a);}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}
ll Power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=mult(c,a,mod);
		b /= 2; a=mult(a,a,mod);
	}
	return c;
}

ll n,x[N],y[N],p[N],w[1<<N],f[1<<N][N],lg[1<<N];

struct rec {
	ll x,y;
	bool operator <(rec b) const {
		return x<b.x;
	}
} a[N];

ll calc(int now) {
	ll tot,s,ans=1e18,tmp,mid;
	
	tot=s=0;
	for(int i=0;i<n;i++)
		if(now>>i&1) a[++tot]=(rec){x[i],p[i]},s+=p[i];
	sort(a+1,a+tot+1);
	mid=s+1>>1;
	for(int i=1;i<=tot;i++)
		if(mid<=a[i].y) {
			tmp=0;
			for(int j=1;j<=tot;j++) tmp+=a[j].y*abs(a[i].x-a[j].x);
			ans=min(ans,tmp); break;
		}
		else mid-=a[i].y;
	
	tot=s=0;
	for(int i=0;i<n;i++)
		if(now>>i&1) a[++tot]=(rec){y[i],p[i]},s+=p[i];
	sort(a+1,a+tot+1);
	mid=s+1>>1;
	for(int i=1;i<=tot;i++)
		if(mid<=a[i].y) {
			tmp=0;
			for(int j=1;j<=tot;j++) tmp+=a[j].y*abs(a[i].x-a[j].x);
			ans=min(ans,tmp); break;
		}
		else mid-=a[i].y;
	
	return ans;
}

int main() {
	qr(n);
	for(int i=0;i<=n;i++) lg[1<<i]=i;
	for(int i=0;i<n;i++)
		qr(x[i]),qr(y[i]),qr(p[i]);
	int s=(1<<n)-1;
	memset(f,63,sizeof f);
	f[0][0]=0;
	for(int i=1;i<=s;i++) {
		f[i][0]=f[i&(i-1)][0];
		int j=lg[i&-i];
		f[i][0] += min(abs(x[j]),abs(y[j]))*p[j];
	}
	pr2(f[s][0]);
	for(int i=1;i<(1<<n);i++) w[i]=calc(i);
	for(int t=1;t<=n;t++) {
 		for(int i=1;i<=s;i++)
			for(int j=i;	;j=(j-1)&i) {
				f[i][t]=min(f[i][t],f[j][t-1]+w[i^j]);
				if(!j) break;
			}
		pr2(f[s][t]);
	}
	return 0;
}

Compiler output:
a.cc:19:10: error: reference to 'size' is ambiguous
   19 | char buf[size],*p1=buf,*p2=buf;
      |          ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:17:16: note:                 'const int size'
   17 | const int N=17,size=1<<20,mod=998244353,inf=2e9;
      |                ^~~~
a.cc:19:20: error: 'buf' was not declared in this scope
   19 | char buf[size],*p1=buf,*p2=buf;
      |                    ^~~