#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
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 |
1 |
Correct |
2 ms |
684 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
700 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
716 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
28 |
Correct |
2 ms |
716 KB |
Output is correct |
29 |
Correct |
2 ms |
704 KB |
Output is correct |
30 |
Correct |
2 ms |
716 KB |
Output is correct |
31 |
Correct |
2 ms |
716 KB |
Output is correct |
32 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
700 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
716 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
28 |
Correct |
2 ms |
716 KB |
Output is correct |
29 |
Correct |
2 ms |
704 KB |
Output is correct |
30 |
Correct |
2 ms |
716 KB |
Output is correct |
31 |
Correct |
2 ms |
716 KB |
Output is correct |
32 |
Correct |
2 ms |
716 KB |
Output is correct |
33 |
Correct |
899 ms |
66184 KB |
Output is correct |
34 |
Correct |
905 ms |
66200 KB |
Output is correct |
35 |
Correct |
932 ms |
66164 KB |
Output is correct |
36 |
Correct |
886 ms |
66148 KB |
Output is correct |
37 |
Correct |
899 ms |
66304 KB |
Output is correct |
38 |
Correct |
965 ms |
66256 KB |
Output is correct |
39 |
Correct |
888 ms |
66180 KB |
Output is correct |
40 |
Correct |
889 ms |
66232 KB |
Output is correct |
41 |
Correct |
880 ms |
66148 KB |
Output is correct |
42 |
Correct |
879 ms |
66192 KB |
Output is correct |
43 |
Correct |
929 ms |
66180 KB |
Output is correct |
44 |
Correct |
928 ms |
66208 KB |
Output is correct |
45 |
Correct |
878 ms |
66224 KB |
Output is correct |
46 |
Correct |
889 ms |
66136 KB |
Output is correct |
47 |
Correct |
899 ms |
66176 KB |
Output is correct |
48 |
Correct |
878 ms |
66256 KB |
Output is correct |
49 |
Correct |
898 ms |
66184 KB |
Output is correct |
50 |
Correct |
888 ms |
66192 KB |
Output is correct |
51 |
Correct |
901 ms |
66236 KB |
Output is correct |
52 |
Correct |
893 ms |
66144 KB |
Output is correct |
53 |
Correct |
877 ms |
66172 KB |
Output is correct |
54 |
Correct |
894 ms |
66232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
708 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
700 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
716 KB |
Output is correct |
26 |
Correct |
2 ms |
716 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
28 |
Correct |
2 ms |
716 KB |
Output is correct |
29 |
Correct |
2 ms |
704 KB |
Output is correct |
30 |
Correct |
2 ms |
716 KB |
Output is correct |
31 |
Correct |
2 ms |
716 KB |
Output is correct |
32 |
Correct |
2 ms |
716 KB |
Output is correct |
33 |
Correct |
899 ms |
66184 KB |
Output is correct |
34 |
Correct |
905 ms |
66200 KB |
Output is correct |
35 |
Correct |
932 ms |
66164 KB |
Output is correct |
36 |
Correct |
886 ms |
66148 KB |
Output is correct |
37 |
Correct |
899 ms |
66304 KB |
Output is correct |
38 |
Correct |
965 ms |
66256 KB |
Output is correct |
39 |
Correct |
888 ms |
66180 KB |
Output is correct |
40 |
Correct |
889 ms |
66232 KB |
Output is correct |
41 |
Correct |
880 ms |
66148 KB |
Output is correct |
42 |
Correct |
879 ms |
66192 KB |
Output is correct |
43 |
Correct |
929 ms |
66180 KB |
Output is correct |
44 |
Correct |
928 ms |
66208 KB |
Output is correct |
45 |
Correct |
878 ms |
66224 KB |
Output is correct |
46 |
Correct |
889 ms |
66136 KB |
Output is correct |
47 |
Correct |
899 ms |
66176 KB |
Output is correct |
48 |
Correct |
878 ms |
66256 KB |
Output is correct |
49 |
Correct |
898 ms |
66184 KB |
Output is correct |
50 |
Correct |
888 ms |
66192 KB |
Output is correct |
51 |
Correct |
901 ms |
66236 KB |
Output is correct |
52 |
Correct |
893 ms |
66144 KB |
Output is correct |
53 |
Correct |
877 ms |
66172 KB |
Output is correct |
54 |
Correct |
894 ms |
66232 KB |
Output is correct |
55 |
Correct |
913 ms |
66204 KB |
Output is correct |
56 |
Correct |
904 ms |
66136 KB |
Output is correct |
57 |
Correct |
900 ms |
66148 KB |
Output is correct |
58 |
Correct |
898 ms |
66196 KB |
Output is correct |
59 |
Correct |
920 ms |
66120 KB |
Output is correct |
60 |
Correct |
917 ms |
66180 KB |
Output is correct |
61 |
Correct |
882 ms |
66168 KB |
Output is correct |
62 |
Correct |
888 ms |
66204 KB |
Output is correct |
63 |
Correct |
906 ms |
66104 KB |
Output is correct |
64 |
Correct |
886 ms |
66180 KB |
Output is correct |
65 |
Incorrect |
902 ms |
66160 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
684 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
716 KB |
Output is correct |
17 |
Correct |
2 ms |
716 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
716 KB |
Output is correct |
20 |
Correct |
2 ms |
716 KB |
Output is correct |
21 |
Correct |
2 ms |
704 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
708 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
316 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
700 KB |
Output is correct |
37 |
Correct |
2 ms |
716 KB |
Output is correct |
38 |
Correct |
2 ms |
716 KB |
Output is correct |
39 |
Correct |
2 ms |
716 KB |
Output is correct |
40 |
Correct |
2 ms |
716 KB |
Output is correct |
41 |
Correct |
2 ms |
716 KB |
Output is correct |
42 |
Correct |
2 ms |
716 KB |
Output is correct |
43 |
Correct |
2 ms |
716 KB |
Output is correct |
44 |
Correct |
2 ms |
704 KB |
Output is correct |
45 |
Correct |
2 ms |
716 KB |
Output is correct |
46 |
Correct |
2 ms |
716 KB |
Output is correct |
47 |
Correct |
2 ms |
716 KB |
Output is correct |
48 |
Correct |
899 ms |
66184 KB |
Output is correct |
49 |
Correct |
905 ms |
66200 KB |
Output is correct |
50 |
Correct |
932 ms |
66164 KB |
Output is correct |
51 |
Correct |
886 ms |
66148 KB |
Output is correct |
52 |
Correct |
899 ms |
66304 KB |
Output is correct |
53 |
Correct |
965 ms |
66256 KB |
Output is correct |
54 |
Correct |
888 ms |
66180 KB |
Output is correct |
55 |
Correct |
889 ms |
66232 KB |
Output is correct |
56 |
Correct |
880 ms |
66148 KB |
Output is correct |
57 |
Correct |
879 ms |
66192 KB |
Output is correct |
58 |
Correct |
929 ms |
66180 KB |
Output is correct |
59 |
Correct |
928 ms |
66208 KB |
Output is correct |
60 |
Correct |
878 ms |
66224 KB |
Output is correct |
61 |
Correct |
889 ms |
66136 KB |
Output is correct |
62 |
Correct |
899 ms |
66176 KB |
Output is correct |
63 |
Correct |
878 ms |
66256 KB |
Output is correct |
64 |
Correct |
898 ms |
66184 KB |
Output is correct |
65 |
Correct |
888 ms |
66192 KB |
Output is correct |
66 |
Correct |
901 ms |
66236 KB |
Output is correct |
67 |
Correct |
893 ms |
66144 KB |
Output is correct |
68 |
Correct |
877 ms |
66172 KB |
Output is correct |
69 |
Correct |
894 ms |
66232 KB |
Output is correct |
70 |
Correct |
913 ms |
66204 KB |
Output is correct |
71 |
Correct |
904 ms |
66136 KB |
Output is correct |
72 |
Correct |
900 ms |
66148 KB |
Output is correct |
73 |
Correct |
898 ms |
66196 KB |
Output is correct |
74 |
Correct |
920 ms |
66120 KB |
Output is correct |
75 |
Correct |
917 ms |
66180 KB |
Output is correct |
76 |
Correct |
882 ms |
66168 KB |
Output is correct |
77 |
Correct |
888 ms |
66204 KB |
Output is correct |
78 |
Correct |
906 ms |
66104 KB |
Output is correct |
79 |
Correct |
886 ms |
66180 KB |
Output is correct |
80 |
Incorrect |
902 ms |
66160 KB |
Output isn't correct |
81 |
Halted |
0 ms |
0 KB |
- |