This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
const int N=2050;
const int M=2*N;
ll l[M],r[M],sum[M],ans[M];
int ls[M],rs[M],tsz,root,A[N];
void pull(int c)
{
ans[c]=max(max(ans[ls[c]],ans[rs[c]]),r[ls[c]]+l[rs[c]]);
l[c]=max(l[ls[c]],sum[ls[c]]+l[rs[c]]);
r[c]=max(r[rs[c]],sum[rs[c]]+r[ls[c]]);
sum[c]=sum[ls[c]]+sum[rs[c]];
}
void Build(int &c, int ss, int se)
{
c=++tsz;
if(ss==se){ sum[c]=A[ss];l[c]=r[c]=ans[c]=max(0,A[ss]);return;}
int mid=ss+se>>1;
Build(ls[c],ss,mid);
Build(rs[c],mid+1,se);
pull(c);
}
void Set(int c, int ss, int se, int qi, int x)
{
if(ss==se){ sum[c]=x;l[c]=r[c]=ans[c]=max(0,x);return;}
int mid=ss+se>>1;
if(qi<=mid) Set(ls[c],ss,mid,qi,x);
else Set(rs[c],mid+1,se,qi,x);
pull(c);
}
struct pt{ ll x,y;pt(){}pt(ll a, ll b):x(a),y(b){}};
bool operator < (pt a, pt b){ return mp(a.y,a.x)<mp(b.y,b.x);}
pt operator - (pt a, pt b){ return pt(a.x-b.x,a.y-b.y);}
ll cross(pt a, pt b){ return a.x*b.y-a.y*b.x;}
ll dot(pt a, pt b){ return a.x*b.x+a.y*b.y;}
ll sq(pt a){ return dot(a,a);}
int part(pt a){ return a<pt(0,0);}
bool comp(pt a, pt b){ return mt(part(a),(ll)0,sq(a))<mt(part(b),cross(a,b),sq(b));}
pt P[N];
int w[N],id[N],pos[N];
int main()
{
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++) scanf("%lld %lld %i",&P[i].x,&P[i].y,&w[i]),id[i]=i;
sort(id+1,id+1+n,[&](int i, int j){ return P[i]<P[j];});
for(int i=1;i<=n;i++) A[i]=w[id[i]],pos[id[i]]=i;
Build(root,1,n);
ll sol=ans[root];
vector<pair<pt,pair<int,int>>> events;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) events.pb({P[i]-P[j],{i,j}});
sort(events.begin(),events.end(),[&](pair<pt,pair<int,int>> a, pair<pt,pair<int,int>> b){ return comp(a.first,b.first);});
for(auto e:events)
{
int x=e.second.first;
int y=e.second.second;
swap(pos[x],pos[y]);
swap(A[pos[x]],A[pos[y]]);
Set(root,1,n,pos[x],A[pos[x]]);
Set(root,1,n,pos[y],A[pos[y]]);
sol=max(sol,ans[root]);
}
printf("%lld\n",sol);
return 0;
}
Compilation message (stderr)
bulldozer.cpp: In function 'void Build(int&, int, int)':
bulldozer.cpp:22:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
bulldozer.cpp: In function 'void Set(int, int, int, int, int)':
bulldozer.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
bulldozer.cpp:49:70: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%lld %lld %i",&P[i].x,&P[i].y,&w[i]),id[i]=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# | 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... |