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 <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct li{
ll x,y;
bool operator<(const li&q)const{
return y*q.x<q.y*x;
}
};
struct qu{
ll x,y,k,a,b;
bool operator<(const qu&q)const{
if(y*q.x!=q.y*x){
if(y==0)return q.x*q.y>0;
if(q.y==0)return x*y<0;
return y*q.x<q.y*x;
}
return k<q.k;
}
};
struct po{
ll x,y,i;
bool operator<(const po&q)const{
if(x!=q.x)return x>q.x;
return y>q.y;
}
};
ll n,k,x[2005],y[2005],w[2005],pl[2005],ans,seg[1<<12],sma[1<<12],smi[1<<12];
vector<P>line[2005];
map<li,ll>o;
vector<qu>q;
vector<po>poi;
void add(int a,ll c){
a+=(1<<11)-1;
sma[a]+=c;
smi[a]+=c;
while(a>0){
a=(a-1)/2;
sma[a]=max(sma[a*2+1],sma[a*2+2]);
smi[a]=min(smi[a*2+1],smi[a*2+2]);
seg[a]=max(max(seg[a*2+1],seg[a*2+2]),sma[a*2+2]-smi[a*2+1]);
}
}
ll que(int a,int b,int l,int r,int v){
if(r<a||b<l)return 0;
if(a<=l&&r<=b)return seg[v];
return max(que(a,b,l,(l+r-1)/2,v*2+1),que(a,b,(l+r+1)/2,r,v*2+2));
}
int main(void){
scanf("%lld",&n);
for(int i=0;i<n;i++)scanf("%lld%lld%lld",x+i,y+i,w+i);
for(int i=0;i<n;i++){
for(int j=0;j<k;j++)line[j].clear();
k=0;
o.clear();
for(int j=i+1;j<n;j++){
if(x[i]==x[j])continue;
li p={x[i]-x[j],y[i]-y[j]};
if(o.find(p)==o.end()){
line[k].PB(P(-x[i],i));
o[p]=k++;
}
line[o[p]].PB(P(-x[j],j));
}
for(int l=0;l<k;l++){
sort(line[l].begin(),line[l].end());
ll e=0;
for(int a=0;a<line[l].size();a++){
for(int b=a+1;b<line[l].size();b++){
int v=line[l][a].S,u=line[l][b].S;
q.PB(qu{x[v]-x[u],y[v]-y[u],e,v,u});
e++;
}
}
}
}
for(int i=0;i<n;i++)poi.PB(po{x[i],y[i],i});
sort(poi.begin(),poi.end());
ll s=0;
for(int i=0;i<n;i++){
s+=w[poi[i].i];
pl[poi[i].i]=i+1;
add(i+1,s);
}
ans=max(ans,que(0,n,0,(1<<11)-1,0));
sort(q.begin(),q.end());
for(int i=0;i<q.size();i++){
vector<P>t;
t.PB(P(q[i].a,q[i].b));
while(i+1<q.size()&&q[i].y*q[i+1].x==q[i+1].y*q[i].x){
i++;
t.PB(P(q[i].a,q[i].b));
}
for(int j=0;j<t.size();j++){
ll a=pl[t[j].F],b=pl[t[j].S],wa=w[t[j].F],wb=w[t[j].S];
pl[t[j].F]=b;
pl[t[j].S]=a;
if(a>b){
swap(a,b);
swap(wa,wb);
}
add(a,-wa+wb);
}
ans=max(ans,que(0,n,0,(1<<11)-1,0));
}
printf("%lld\n",ans);
}
Compilation message (stderr)
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:77:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int a=0;a<line[l].size();a++){
~^~~~~~~~~~~~~~~
bulldozer.cpp:78:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int b=a+1;b<line[l].size();b++){
~^~~~~~~~~~~~~~~
bulldozer.cpp:96:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<q.size();i++){
~^~~~~~~~~
bulldozer.cpp:99:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i+1<q.size()&&q[i].y*q[i+1].x==q[i+1].y*q[i].x){
~~~^~~~~~~~~
bulldozer.cpp:103:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<t.size();j++){
~^~~~~~~~~
bulldozer.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
bulldozer.cpp:60:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0;i<n;i++)scanf("%lld%lld%lld",x+i,y+i,w+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... |