传送门
很显然的结论,\((x,y)\)与\((y,x)\)关于\(y=x\)对称
那么就可以知道矩形一定是在直线的一侧
有一些点可以不需要动,那么第二问分四种情况讨论即可
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e6+1;
int n,x[maxn],y[maxn],z[maxn],ans1,ans2=2e9,a=2e9,b,c=2e9,d,f[maxn],g[maxn];
void calc(int a,int b,int c,int d)
{
ans1=0;memset(f,0,sizeof f);
for(rg int i=1;i<=n;i++)
{
if(a<=x[i]&&x[i]<=b&&y[i]>=c&&y[i]<=d)continue;
if(a<=y[i]&&y[i]<=b&&x[i]>=c&&x[i]<=d)ans1+=z[i],f[i]=1;
else return ;
}
if(ans1<ans2)memcpy(g,f,sizeof f),ans2=ans1;
}
int main()
{
read(n);
for(rg int i=1;i<=n;i++)
{
read(x[i]),read(y[i]),read(z[i]);
if(x[i]>y[i])a=min(y[i],a),b=max(y[i],b),c=min(x[i],c),d=max(d,x[i]);
else a=min(a,x[i]),b=max(x[i],b),c=min(y[i],c),d=max(d,y[i]);
}
calc(a,b,c,d),calc(a,d,c,b),calc(c,b,a,d),calc(c,d,a,b);
printf("%lld %d\n",(b-a+d-c)*2ll,ans2);
for(rg int i=1;i<=n;i++)printf("%d",g[i]);
}