1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include<bits/stdc++.h> using namespace std; #define P pair<int,int> #define fir first #define sec second const int maxn=5e5; int n,K; int a[maxn+5],b[maxn+5],c[maxn+5]; P va[maxn+5],vb[maxn+5],vc[maxn+5]; bool vis[maxn+5]; inline int Calc(int pa,int pb,int pc,int ta,int tb,int tc){ return max({ta-pa,tb-pb,tc-pc}); } signed main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d%d",&a[i],&b[i],&c[i]); va[i]=P(a[i],i); vb[i]=P(b[i],i); vc[i]=P(c[i],i); } a[n+1]=b[n+1]=c[n+1]=1e9+7; va[n+1]=vb[n+1]=vc[n+1]=P(1e9+7,n+1); sort(va+1,va+n+1); sort(vb+1,vb+n+1); sort(vc+1,vc+n+1); for(int i=1,j=1,k=1;i<=n||j<=n||k<=n;){ while(vis[va[i].sec]) i++; while(vis[vb[j].sec]) j++; while(vis[vc[k].sec]) k++; int ti=Calc(va[i].fir,vb[j].fir,vc[k].fir ,a[va[i].sec],b[va[i].sec],c[va[i].sec]); int tj=Calc(va[i].fir,vb[j].fir,vc[k].fir ,a[vb[j].sec],b[vb[j].sec],c[vb[j].sec]); int tk=Calc(va[i].fir,vb[j].fir,vc[k].fir ,a[vc[k].sec],b[vc[k].sec],c[vc[k].sec]); int tt=min({ti,tj,tk}); K=max(K,tt); if(ti==tt) vis[va[i].sec]=1; else if(tj==tt) vis[vb[j].sec]=1; else vis[vc[k].sec]=1; } printf("%d",(int)ceil(K/2.0)); return 0; }
|