이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int nmax=2005;
struct point
{
long long x,y,val;
}v[nmax];
struct line
{
long long nr,nm;
int i1,i2;
}pp[nmax*nmax/2];
struct node
{
long long mxsuf,mxpref,sum,mx;
}arb[4*nmax],ans;
bool compP(point unu,point doi)
{
if(unu.x==doi.x) return unu.y>doi.y;
return (unu.x>doi.x);
}
bool compL(line unu,line doi)
{
if((1LL*unu.nr*doi.nm==1LL*unu.nm*doi.nr))
{
if(unu.i1==doi.i1) return unu.i2<doi.i2;
return unu.i1<doi.i1;
}
return (1LL*unu.nr*doi.nm<1LL*unu.nm*doi.nr);
}
int ord[nmax];
long long A[nmax];
int n,i,j,nr,I,J,poz;
long long act,mx;
void mrg(node &A,node B,node C)
{
A.sum=1LL*B.sum+C.sum;
A.mxpref=max(B.mxpref,B.sum+C.mxpref);
A.mxsuf=max(C.mxsuf,C.sum+B.mxsuf);
A.mx=max(B.mx,C.mx);
A.mx=max(A.mx,B.mxsuf+C.mxpref);
}
void update(int nod,int l,int r,int poz,long long val)
{
if(l==r)
{
arb[nod].mx=max(val,0LL);
arb[nod].mxpref=arb[nod].mxsuf=max(val,0LL);
arb[nod].sum=val;
return;
}
int m=(l+r)/2;
if(poz<=m) update(2*nod,l,m,poz,val);
else update(2*nod+1,m+1,r,poz,val);
mrg(arb[nod],arb[2*nod],arb[2*nod+1]);
}
int abss(int x)
{
if(x<0) return -x;
return x;
}
int main()
{
//freopen("data.in","r",stdin);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i].x>>v[i].y>>v[i].val;
}
sort(v+1,v+n+1,compP);
for(i=1;i<=n;i++)
{
ord[i]=i;
update(1,1,n,i,v[i].val);
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(v[i].x!=v[j].x)
{
pp[++nr]={v[j].y-v[i].y,v[j].x-v[i].x,i,j};
if(pp[nr].nm<0)
pp[nr].nr*=-1,pp[nr].nm*=-1;
}
mx=arb[1].mx;
sort(pp+1,pp+nr+1,compL);
int lim;
for(i=1;i<=nr;i++)
{
for(j=i;j<=nr&&1LL*pp[i].nm*pp[j].nr==1LL*pp[i].nr*pp[j].nm;j++);
j--;
lim=j;
for(j=i;j<=lim;j++)
{
I=pp[j].i1;
J=pp[j].i2;
swap(ord[I],ord[J]);
poz=min(ord[I],ord[J]);
update(1,1,n,ord[I],v[I].val);
update(1,1,n,ord[J],v[J].val);
}
mx=max(mx,arb[1].mx);
i=lim;
}
cout<<mx;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |