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;
#define ar array
#define int long long
const int N = 2005;
long double const eps = 1e-18;
struct ST{
ar<int, 4> tree[N * 4];
void merge(ar<int, 4>& x, ar<int, 4>& a, ar<int, 4>& b){
x[0] = max({a[0], b[0], a[2] + b[1]});
x[1] = max({a[1], a[3] + b[1]});
x[2] = max({b[2], b[3] + a[2]});
x[3] = a[3] + b[3];
}
void sett(int i, int v, int lx = 0, int rx = N, int x = 1){
if(lx == rx){
tree[x] = {max(v, 0ll), max(v, 0ll), max(v, 0ll), v}; return;
} int m = (lx + rx) >> 1;
if(i <= m) sett(i, v, lx, m, x<<1);
else sett(i, v, m+1, rx, x<<1|1);
merge(tree[x], tree[x<<1], tree[x<<1|1]);
}
}tree;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<ar<int, 3>> a(n);
for(int i=0;i<n;i++){
cin>>a[i][0]>>a[i][1]>>a[i][2];
} sort(a.begin(), a.end());
vector<pair<long double, pair<int, int>>> tt;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(a[i][0] == a[j][0]) continue;
double slop = (a[j][1] - a[i][1]) * 1. / (a[i][0] - a[j][0]);
tt.push_back({slop, {i, j}});
}
}
vector<long double> b(n);
vector<int> p(n); iota(p.begin(), p.end(), 0);
for(int i=0;i<n;i++){
b[i] = a[i][1] * 1. - (a[i][0] * -2e9);
}
sort(p.begin(), p.end(), [&](int i, int j){
return (eps < b[j] - b[i]);
});
vector<int> pos(n);
for(int i=0;i<n;i++) pos[p[i]] = i, tree.sett(i, a[p[i]][2]);
int res = tree.tree[1][0];
sort(tt.begin(), tt.end());
for(int l=0;l<(int)tt.size();){
int k = l;
while(k < (int)tt.size() && tt[k].first == tt[l].first){
auto [i, j] = tt[k].second;
swap(p[pos[i]], p[pos[j]]);
swap(pos[i], pos[j]); k++;
tree.sett(pos[i], a[i][2]), tree.sett(pos[j], a[j][2]);
} l = k;
res = max(res, tree.tree[1][0]);
}
cout<<res<<"\n";
}
Compilation message (stderr)
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:65:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 | auto [i, j] = tt[k].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... |