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>
#define all(v) v.begin(),v.end()
#define eb emplace_back
using namespace std;
using ll=long long;
using P=pair<int,int>;
using C=complex<double>;
void chmax(ll &a,ll b){a=max(a,b);}
void chmin(ll &a,ll b){a=min(a,b);}
struct segtree{
int n;
vector<ll> dat;
segtree(int n):n(n){
dat.resize(n);
}
void upd(int k,ll x){
dat[k]=x;
}
ll get(){
ll sum=0,mi=0,res=0;
for(int i=0;i<n;i++){
sum+=dat[i];
chmax(res,sum-mi);
chmin(mi,sum);
}
return res;
}
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;cin>>n;
assert(n<=100);
vector<double> x(n),y(n);
vector<ll> w(n);
vector<pair<double,P>> v;
vector<P> ps(n);
for(int i=0;i<n;i++){
cin>>x[i]>>y[i]>>w[i];
ps[i].first=y[i];
ps[i].second=i;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
double t=atan2(y[j]-y[i],x[j]-x[i]);
if(t>=0){
v.eb(t,P(i,j));
}
}
}
sort(all(v));
sort(all(ps));
reverse(all(ps));
segtree seg(n);
vector<int> pos(n);
for(int i=0;i<n;i++){
seg.upd(i,w[ps[i].second]);
pos[ps[i].second]=i;
}
ll res=seg.get();
for(int i=0;i<v.size();i++){
int l=v[i].second.first,r=v[i].second.second;
swap(pos[l],pos[r]);
seg.upd(pos[l],w[l]);
seg.upd(pos[r],w[r]);
chmax(res,seg.get());
}
cout<<res<<'\n';
}
Compilation message (stderr)
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:62:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();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... |