#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;
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 = t[1].mx;
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 |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
584 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
4 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Incorrect |
1 ms |
284 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
4 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Incorrect |
1 ms |
284 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
4 ms |
596 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Incorrect |
1 ms |
284 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
584 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |