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;
using ll = long long;
#define mid ((l+r) >> 1)
struct point{
ll x, y, w;
bool operator < (const point &o) const{
return tie(x, y) < tie(o.x, o.y);
}
};
struct line{
int i, j;
ll dx, dy;
bool operator < (const line &o) const{
return make_tuple(dy * o.dx, i, j) < make_tuple(o.dy * dx, o.i, o.j);
}
bool operator == (const line &o) const{
return dy * o.dx == o.dy * dx;
}
};
struct node{
ll mx, l, r, s;
node operator + (const node &o) const{
return {max({mx, o.mx, r+o.l}), max(l, s+o.l), max(o.r, o.s+r), s+o.s};
}
} t[8080];
int n;
void update(int id, ll w, int node = 1, int l = 1, int r = n){
if(id < l || r < id) return;
if(l == r){
t[node] = {w, w, w, w};
return;
}
update(id, w, node*2, l, mid), update(id, w, node*2+1, mid+1, r);
t[node] = t[node*2] + t[node*2+1];
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
vector<point> v(n);
for(auto &[x, y, w] : v) cin >> x >> y >> w;
if(n == 1) return cout << max(0ll, v[0].w), 0;
sort(v.begin(), v.end());
vector<int> p(n); iota(p.begin(), p.end(), 0);
for(int i=0;i<n;i++) update(i+1, v[i].w);
vector<line> l;
for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) l.push_back({i, j, v[j].x-v[i].x, v[j].y-v[i].y});
sort(l.begin(), l.end());
int m = l.size();
ll ans = 0;
for(int i=0;i<m;i++){
int j = i;
while(j+1 < m && l[i] == l[j+1]) j++;
for(int k=i;k<=j;k++){
int a = l[k].i, b = l[k].j;
swap(p[a], p[b]), swap(v[p[a]], v[p[b]]);
update(p[a]+1, v[p[a]].w), update(p[b]+1, v[p[b]].w);
}
ans = max(ans, t[1].mx);
i = j;
}
cout << ans;
}
# | 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... |