#include <bits/stdc++.h>
using namespace std;
struct pt {
int x, y;
};
bool same(int x1, int y1, int x2, int y2) {
// y1 / x1 = y2 / x2
return x1 * 1LL * y2 == y1 * 1LL * x2;
}
long long cross(pt a, pt b) {
return a.x * 1LL * b.y - a.y * 1LL * b.x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> x(n), y(n), w(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> w[i];
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
if (y[i] != y[j]) {
return y[i] < y[j];
} else {
return x[i] < x[j];
}
});
vector<int> pos(n);
for (int i = 0; i < n; i++) {
pos[order[i]] = i;
}
vector<long long> mx(4 * n);
vector<long long> sum(4 * n);
vector<long long> pref(4 * n);
vector<long long> suff(4 * n);
auto Pull = [&](int x) {
sum[x] = sum[x << 1] + sum[x << 1 | 1];
mx[x] = max({mx[x << 1], mx[x << 1 | 1], suff[x << 1] + pref[x << 1 | 1]});
pref[x] = max(pref[x << 1], sum[x << 1] + pref[x << 1 | 1]);
suff[x] = max(suff[x << 1 | 1], sum[x << 1 | 1] + suff[x << 1]);
};
function<void(int, int, int)> Build = [&](int x, int l, int r) {
if (l == r) {
sum[x] = w[order[l]];
mx[x] = max(0LL, sum[x]);
pref[x] = max(0LL, sum[x]);
suff[x] = max(0LL, sum[x]);
return;
}
int mid = l + r >> 1;
Build(x << 1, l, mid);
Build(x << 1 | 1, mid + 1, r);
Pull(x);
};
function<void(int, int, int, int)> Update = [&](int x, int l, int r, int p) {
if (l == r) {
sum[x] = w[order[l]];
mx[x] = max(0LL, sum[x]);
pref[x] = max(0LL, sum[x]);
suff[x] = max(0LL, sum[x]);
return;
}
int mid = l + r >> 1;
if (p <= mid) {
Update(x << 1, l, mid, p);
} else {
Update(x << 1 | 1, mid + 1, r, p);
}
Pull(x);
};
Build(1, 0, n - 1);
vector<array<int, 4>> qs;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int fx = x[j] - x[i];
int fy = y[j] - y[i];
if (fy < 0 || (fy == 0 && fx < 0)) {
fx = -fx;
fy = -fy;
}
qs.push_back({fx, fy, i, j});
}
}
sort(qs.begin(), qs.end(), [&](array<int, 4> a, array<int, 4> b) {
pt p;
p.x = a[0];
p.y = a[1];
pt q;
q.x = b[0];
q.y = b[1];
return cross(p, q) > 0;
});
int sz = (int) qs.size();
long long ans = mx[1];
for (int i = 0; i < sz; i++) {
int ptr = i;
while (ptr < sz && same(qs[i][0], qs[i][1], qs[ptr][0], qs[ptr][1])) {
swap(order[pos[qs[ptr][2]]], order[pos[qs[ptr][3]]]);
swap(pos[qs[ptr][2]], pos[qs[ptr][3]]);
Update(1, 0, n - 1, pos[qs[ptr][2]]);
Update(1, 0, n - 1, pos[qs[ptr][3]]);
ptr += 1;
}
ans = max(ans, mx[1]);
i = ptr - 1;
}
cout << ans << '\n';
return 0;
}
Compilation message
bulldozer.cpp: In lambda function:
bulldozer.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int mid = l + r >> 1;
| ~~^~~
bulldozer.cpp: In lambda function:
bulldozer.cpp:71:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
520 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
520 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
936 ms |
35264 KB |
Output is correct |
34 |
Correct |
933 ms |
34496 KB |
Output is correct |
35 |
Correct |
941 ms |
35008 KB |
Output is correct |
36 |
Correct |
930 ms |
35008 KB |
Output is correct |
37 |
Correct |
934 ms |
33728 KB |
Output is correct |
38 |
Correct |
931 ms |
33724 KB |
Output is correct |
39 |
Correct |
940 ms |
35520 KB |
Output is correct |
40 |
Correct |
938 ms |
35264 KB |
Output is correct |
41 |
Correct |
934 ms |
34740 KB |
Output is correct |
42 |
Correct |
928 ms |
35520 KB |
Output is correct |
43 |
Correct |
926 ms |
34236 KB |
Output is correct |
44 |
Correct |
928 ms |
35520 KB |
Output is correct |
45 |
Correct |
936 ms |
34228 KB |
Output is correct |
46 |
Correct |
940 ms |
34752 KB |
Output is correct |
47 |
Correct |
952 ms |
35008 KB |
Output is correct |
48 |
Correct |
952 ms |
34240 KB |
Output is correct |
49 |
Correct |
960 ms |
34236 KB |
Output is correct |
50 |
Correct |
961 ms |
34168 KB |
Output is correct |
51 |
Correct |
932 ms |
34752 KB |
Output is correct |
52 |
Correct |
924 ms |
33984 KB |
Output is correct |
53 |
Correct |
929 ms |
34752 KB |
Output is correct |
54 |
Correct |
922 ms |
34572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
520 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
936 ms |
35264 KB |
Output is correct |
34 |
Correct |
933 ms |
34496 KB |
Output is correct |
35 |
Correct |
941 ms |
35008 KB |
Output is correct |
36 |
Correct |
930 ms |
35008 KB |
Output is correct |
37 |
Correct |
934 ms |
33728 KB |
Output is correct |
38 |
Correct |
931 ms |
33724 KB |
Output is correct |
39 |
Correct |
940 ms |
35520 KB |
Output is correct |
40 |
Correct |
938 ms |
35264 KB |
Output is correct |
41 |
Correct |
934 ms |
34740 KB |
Output is correct |
42 |
Correct |
928 ms |
35520 KB |
Output is correct |
43 |
Correct |
926 ms |
34236 KB |
Output is correct |
44 |
Correct |
928 ms |
35520 KB |
Output is correct |
45 |
Correct |
936 ms |
34228 KB |
Output is correct |
46 |
Correct |
940 ms |
34752 KB |
Output is correct |
47 |
Correct |
952 ms |
35008 KB |
Output is correct |
48 |
Correct |
952 ms |
34240 KB |
Output is correct |
49 |
Correct |
960 ms |
34236 KB |
Output is correct |
50 |
Correct |
961 ms |
34168 KB |
Output is correct |
51 |
Correct |
932 ms |
34752 KB |
Output is correct |
52 |
Correct |
924 ms |
33984 KB |
Output is correct |
53 |
Correct |
929 ms |
34752 KB |
Output is correct |
54 |
Correct |
922 ms |
34572 KB |
Output is correct |
55 |
Correct |
937 ms |
34748 KB |
Output is correct |
56 |
Correct |
934 ms |
35264 KB |
Output is correct |
57 |
Correct |
953 ms |
33984 KB |
Output is correct |
58 |
Correct |
927 ms |
34308 KB |
Output is correct |
59 |
Correct |
928 ms |
34372 KB |
Output is correct |
60 |
Correct |
931 ms |
35008 KB |
Output is correct |
61 |
Correct |
927 ms |
34240 KB |
Output is correct |
62 |
Correct |
928 ms |
34496 KB |
Output is correct |
63 |
Correct |
930 ms |
35004 KB |
Output is correct |
64 |
Correct |
931 ms |
35520 KB |
Output is correct |
65 |
Correct |
950 ms |
35004 KB |
Output is correct |
66 |
Correct |
928 ms |
34760 KB |
Output is correct |
67 |
Correct |
933 ms |
35516 KB |
Output is correct |
68 |
Correct |
932 ms |
35768 KB |
Output is correct |
69 |
Correct |
932 ms |
34752 KB |
Output is correct |
70 |
Correct |
934 ms |
34748 KB |
Output is correct |
71 |
Correct |
927 ms |
33984 KB |
Output is correct |
72 |
Correct |
932 ms |
34100 KB |
Output is correct |
73 |
Correct |
929 ms |
34756 KB |
Output is correct |
74 |
Correct |
927 ms |
34236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |