思路很简单
枚举端点极角排序后扫一遍就完了
但是细节有点多
首先有竖着的情况,斜率会炸
还要考虑上下两边的情况
一种巧妙的方法是把斜率取倒数,即变成
我们会发现这样从小到大排序做就解决所有问题了
还有端点挨在一起也算,所以可以把所有出的地方加一个
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define re register
#define pb push_back
#define cs const
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?(a+=mod):0;}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int ksm(int a,int b,int res=1){
for(;b;b>>=1,a=mul(a,a))(b&1)&&(res=mul(res,a));return res;
}
inline void chemx(ll &a,ll b){
a<b?a=b:0;
}
inline void chemn(int &a,int b){
a>b?a=b:0;
}
cs int N=4005;
cs double eps=1e-8;
struct node{
double k;int v;
friend inline bool operator <(cs node &a,cs node &b){
return a.k<b.k;
}
}p[N];
int n,a[N],tot,x[2][N],y[N],*X;
ll ans;
inline void get(int i,int j){
p[++tot].k=(double)(x[0][j]-X[i])/(double)(y[j]-y[i]);
p[++tot].k=(double)(x[1][j]-X[i])/(double)(y[j]-y[i]);
if(p[tot].k>p[tot-1].k){
p[tot].v=-a[j],p[tot-1].v=a[j],p[tot].k+=eps;
}
else p[tot].v=a[j],p[tot-1].v=-a[j],p[tot-1].k+=eps;
}
int main(){
n=read();
for(int i=1;i<=n;i++){
x[0][i]=read(),x[1][i]=read();
if(x[0][i]>x[1][i])swap(x[0][i],x[1][i]);
y[i]=read(),a[i]=x[1][i]-x[0][i];
}
for(int i=1;i<=n;i++){
tot=0,X=x[0];
for(int j=1;j<=n;j++){
if(y[i]!=y[j])get(i,j);
}
sort(p+1,p+tot+1);
ll res=a[i];
chemx(ans,res);
for(int j=1;j<=tot;j++){
res+=p[j].v;
chemx(ans,res);
}
X=x[1],tot=0,res=a[i];
for(int j=1;j<=n;j++){
if(y[i]!=y[j])get(i,j);
}
sort(p+1,p+tot+1);
for(int j=1;j<=tot;j++){
res+=p[j].v;
chemx(ans,res);
}
}
cout<<ans;
}