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<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int lld;
typedef pair<pair<lld,lld>,lld> piii;
int n;
int cmp(pair<pair<lld,lld>,pair<int,int> > x, pair<pair<lld,lld>,pair<int,int> > y){
if(x.first.first*y.first.second>x.first.second*y.first.first){
return true;
}return false;
}
lld segtreeSUM[4000000];
lld segtreePR[4000000];
lld segtreeSU[4000000];
lld segtreeANS[4000000];
void build(int a, int b, int node){
segtreeANS[node]=0;
segtreePR[node]=0;
segtreeSU[node]=0;
segtreeSUM[node]=0;
if(a==b)return;
int mid=(a+b)/2;
build(a,mid,2*node);
build(mid+1,b,2*node+1);
}
void Build(){
build(0,n-1,1);
}
void update(int a, int b, int node, int pos,lld val){
if(a>pos || b<pos)return;
if(a==b){
segtreeSUM[node]=val;
segtreeANS[node]=max(val,(lld)0);
segtreePR[node]=segtreeANS[node];
segtreeSU[node]=segtreeANS[node];
return;
}
int mid=(a+b)/2;
update(a,mid,2*node,pos,val);
update(mid+1,b,2*node+1,pos,val);
segtreeSUM[node]=segtreeSUM[2*node]+segtreeSUM[2*node+1];
segtreePR[node]=max(segtreePR[2*node],segtreeSUM[2*node]+segtreePR[2*node+1]);
segtreeSU[node]=max(segtreeSU[2*node+1],segtreeSUM[2*node+1]+segtreeSU[2*node]);
segtreeANS[node]=max(segtreeANS[2*node],segtreeANS[2*node+1]);
segtreeANS[node]=max(segtreeANS[node],segtreeSU[2*node]+segtreePR[2*node+1]);
}
void Update(int pos, lld val){
update(0,n-1,1,pos,val);
}
lld query(){
return segtreeANS[1];
}
int main(){
scanf("%d",&n);
piii arr[n];
bool b=true;
for(int i=0;i<n;i++){
scanf("%lld %lld %lld",&arr[i].first.first,&arr[i].first.second,&arr[i].second);
if(arr[i].first.second!=0)b=false;
}sort(arr,arr+n);
if(b){
lld ans=0;
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
lld can=0;
for(int k=i;k<=j;k++){
can+=arr[k].second;
}ans=max(ans,can);
}
}printf("%lld\n",ans);
return 0;
}
lld ans=0;
if(n==1){
if(arr[0].second>0){
cout<<arr[0].second<<endl;
return 0;
}cout<<0<<endl;
return 0;
}
vector<pair<pair<lld,lld>,pair<int,int> > > array;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
pair<lld,lld> p1=pair<lld,lld>(arr[j].first.second-arr[i].first.second,arr[j].first.first-arr[i].first.first);
array.push_back(pair<pair<lld,lld>,pair<int,int> >(p1,pair<int,int>(i,j)));
}
}sort(array.begin(),array.end(),cmp);
/*for(int i=0;i<array.size();i++){
cout<<array[i].first.first<<" "<<array[i].first.second<<" "<<array[i].second.first<<" "<<array[i].second.second<<endl;
}*/
pair<int,int> changes[array.size()];
for(int i=0;i<array.size();i++){
changes[i].first=array[i].second.first;
changes[i].second=array[i].second.second;
}
int per[n];
for(int i=0;i<n;i++)per[i]=i;
Build();
for(int i=0;i<n;i++)Update(i,arr[i].second);
//cout<<query()<<endl;
for(int i=0;i<array.size();i++){
int x=changes[i].first;
int y=changes[i].second;
Update(per[x],arr[y].second);
Update(per[y],arr[x].second);
swap(per[x],per[y]);
ans=max(ans,query());
}cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:101:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<array.size();i++){
~^~~~~~~~~~~~~
bulldozer.cpp:110:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<array.size();i++){
~^~~~~~~~~~~~~
bulldozer.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
bulldozer.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&arr[i].first.first,&arr[i].first.second,&arr[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |