#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 i = order[_i];
int j = order[_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];
if (cross(p, q) == 0) {
return make_pair(a[2], a[3]) < make_pair(b[2], b[3]);
}
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;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
604 KB |
Output is correct |
5 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 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 |
604 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 |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 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 |
684 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 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 |
604 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 |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 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 |
684 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
945 ms |
33712 KB |
Output is correct |
34 |
Correct |
941 ms |
33984 KB |
Output is correct |
35 |
Correct |
950 ms |
33728 KB |
Output is correct |
36 |
Correct |
956 ms |
33728 KB |
Output is correct |
37 |
Correct |
945 ms |
34748 KB |
Output is correct |
38 |
Correct |
937 ms |
35260 KB |
Output is correct |
39 |
Correct |
949 ms |
33724 KB |
Output is correct |
40 |
Correct |
942 ms |
33728 KB |
Output is correct |
41 |
Correct |
958 ms |
34240 KB |
Output is correct |
42 |
Correct |
939 ms |
34300 KB |
Output is correct |
43 |
Correct |
933 ms |
35260 KB |
Output is correct |
44 |
Correct |
934 ms |
35004 KB |
Output is correct |
45 |
Correct |
953 ms |
35264 KB |
Output is correct |
46 |
Correct |
938 ms |
34240 KB |
Output is correct |
47 |
Correct |
948 ms |
34752 KB |
Output is correct |
48 |
Correct |
944 ms |
35520 KB |
Output is correct |
49 |
Correct |
935 ms |
34496 KB |
Output is correct |
50 |
Correct |
939 ms |
35260 KB |
Output is correct |
51 |
Correct |
934 ms |
34996 KB |
Output is correct |
52 |
Correct |
932 ms |
35516 KB |
Output is correct |
53 |
Correct |
935 ms |
34496 KB |
Output is correct |
54 |
Correct |
938 ms |
35004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 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 |
604 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 |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 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 |
684 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
945 ms |
33712 KB |
Output is correct |
34 |
Correct |
941 ms |
33984 KB |
Output is correct |
35 |
Correct |
950 ms |
33728 KB |
Output is correct |
36 |
Correct |
956 ms |
33728 KB |
Output is correct |
37 |
Correct |
945 ms |
34748 KB |
Output is correct |
38 |
Correct |
937 ms |
35260 KB |
Output is correct |
39 |
Correct |
949 ms |
33724 KB |
Output is correct |
40 |
Correct |
942 ms |
33728 KB |
Output is correct |
41 |
Correct |
958 ms |
34240 KB |
Output is correct |
42 |
Correct |
939 ms |
34300 KB |
Output is correct |
43 |
Correct |
933 ms |
35260 KB |
Output is correct |
44 |
Correct |
934 ms |
35004 KB |
Output is correct |
45 |
Correct |
953 ms |
35264 KB |
Output is correct |
46 |
Correct |
938 ms |
34240 KB |
Output is correct |
47 |
Correct |
948 ms |
34752 KB |
Output is correct |
48 |
Correct |
944 ms |
35520 KB |
Output is correct |
49 |
Correct |
935 ms |
34496 KB |
Output is correct |
50 |
Correct |
939 ms |
35260 KB |
Output is correct |
51 |
Correct |
934 ms |
34996 KB |
Output is correct |
52 |
Correct |
932 ms |
35516 KB |
Output is correct |
53 |
Correct |
935 ms |
34496 KB |
Output is correct |
54 |
Correct |
938 ms |
35004 KB |
Output is correct |
55 |
Correct |
944 ms |
33984 KB |
Output is correct |
56 |
Correct |
939 ms |
35520 KB |
Output is correct |
57 |
Correct |
940 ms |
34232 KB |
Output is correct |
58 |
Correct |
940 ms |
33724 KB |
Output is correct |
59 |
Correct |
946 ms |
35764 KB |
Output is correct |
60 |
Correct |
950 ms |
35004 KB |
Output is correct |
61 |
Correct |
973 ms |
35008 KB |
Output is correct |
62 |
Correct |
940 ms |
34240 KB |
Output is correct |
63 |
Correct |
969 ms |
34748 KB |
Output is correct |
64 |
Correct |
940 ms |
35260 KB |
Output is correct |
65 |
Correct |
945 ms |
35004 KB |
Output is correct |
66 |
Correct |
948 ms |
33980 KB |
Output is correct |
67 |
Correct |
945 ms |
34348 KB |
Output is correct |
68 |
Correct |
966 ms |
35528 KB |
Output is correct |
69 |
Correct |
985 ms |
35008 KB |
Output is correct |
70 |
Correct |
986 ms |
35520 KB |
Output is correct |
71 |
Correct |
998 ms |
35008 KB |
Output is correct |
72 |
Correct |
953 ms |
35260 KB |
Output is correct |
73 |
Correct |
953 ms |
35264 KB |
Output is correct |
74 |
Correct |
947 ms |
34748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
604 KB |
Output is correct |
5 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |