#include <bits/stdc++.h>
using namespace std;
#define int long long
struct T {
int l, r, sum, ans;
T operator+(T he) { return {max(l, sum + he.l), max(r + he.sum, he.r), sum + he.sum, max({ans, he.ans, r + he.l})}; }
void ini(int v)
{
sum = v;
l = r = ans = max(0LL, v);
}
};
struct P {
int x, y, add;
bool operator<(P he) { return tie(x, y) < tie(he.x, he.y); }
void read() { cin >> x >> y >> add; }
};
struct V {
int dx, dy, a, b;
bool operator<(V he) { return make_tuple(dy * he.dx, a) < make_tuple(he.dy * dx, he.a); }
};
int n;
vector<T> tree;
vector<P> points;
#define m (l + r) / 2
#define lc 2 * v
#define rc 2 * v + 1
void build(int v = 1, int l = 0, int r = n - 1)
{
if(l == r) {
tree[v].ini(points[l].add);
}
else {
build(lc, l, m), build(rc, m + 1, r);
tree[v] = tree[lc] + tree[rc];
}
}
void update(int where, int to, int v = 1, int l = 0, int r = n - 1)
{
if(l == r) {
tree[v].ini(to);
}
else {
if(where <= m) {
update(where, to, lc, l, m);
}
else {
update(where, to, rc, m + 1, r);
}
tree[v] = tree[lc] + tree[rc];
}
}
#undef m
#undef lc
#undef rc
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
points.resize(n);
tree.resize(4 * n);
vector<int> gdz(n);
for(int i = 0; i < n; i++) {
points[i].read();
gdz[i] = i;
}
sort(points.begin(), points.end());
vector<V> wek;
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
wek.push_back({points[j].x - points[i].x, points[j].y - points[i].y, i, j});
}
}
sort(wek.begin(), wek.end());
build();
int ans = tree[1].ans;
int m = (int)wek.size();
for(int i = 0; i < m; i++) {
auto [a, b] = tie(wek[i].a, wek[i].b);
update(gdz[a], points[b].add);
update(gdz[b], points[a].add);
swap(gdz[a], gdz[b]);
if(i == m - 1 || wek[i].dy * wek[i + 1].dx != wek[i + 1].dy * wek[i].dx) {
ans = max(ans, tree[1].ans);
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
757 ms |
66456 KB |
Output is correct |
34 |
Correct |
741 ms |
66376 KB |
Output is correct |
35 |
Correct |
769 ms |
66408 KB |
Output is correct |
36 |
Correct |
749 ms |
66376 KB |
Output is correct |
37 |
Correct |
779 ms |
66448 KB |
Output is correct |
38 |
Correct |
740 ms |
66416 KB |
Output is correct |
39 |
Correct |
741 ms |
66464 KB |
Output is correct |
40 |
Correct |
746 ms |
66460 KB |
Output is correct |
41 |
Correct |
731 ms |
66416 KB |
Output is correct |
42 |
Correct |
745 ms |
66444 KB |
Output is correct |
43 |
Correct |
744 ms |
66372 KB |
Output is correct |
44 |
Correct |
741 ms |
66448 KB |
Output is correct |
45 |
Correct |
744 ms |
66432 KB |
Output is correct |
46 |
Correct |
744 ms |
66412 KB |
Output is correct |
47 |
Correct |
733 ms |
66396 KB |
Output is correct |
48 |
Correct |
740 ms |
66436 KB |
Output is correct |
49 |
Correct |
738 ms |
66412 KB |
Output is correct |
50 |
Correct |
734 ms |
66336 KB |
Output is correct |
51 |
Correct |
748 ms |
66448 KB |
Output is correct |
52 |
Correct |
732 ms |
66448 KB |
Output is correct |
53 |
Correct |
735 ms |
66388 KB |
Output is correct |
54 |
Correct |
734 ms |
66380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
757 ms |
66456 KB |
Output is correct |
34 |
Correct |
741 ms |
66376 KB |
Output is correct |
35 |
Correct |
769 ms |
66408 KB |
Output is correct |
36 |
Correct |
749 ms |
66376 KB |
Output is correct |
37 |
Correct |
779 ms |
66448 KB |
Output is correct |
38 |
Correct |
740 ms |
66416 KB |
Output is correct |
39 |
Correct |
741 ms |
66464 KB |
Output is correct |
40 |
Correct |
746 ms |
66460 KB |
Output is correct |
41 |
Correct |
731 ms |
66416 KB |
Output is correct |
42 |
Correct |
745 ms |
66444 KB |
Output is correct |
43 |
Correct |
744 ms |
66372 KB |
Output is correct |
44 |
Correct |
741 ms |
66448 KB |
Output is correct |
45 |
Correct |
744 ms |
66432 KB |
Output is correct |
46 |
Correct |
744 ms |
66412 KB |
Output is correct |
47 |
Correct |
733 ms |
66396 KB |
Output is correct |
48 |
Correct |
740 ms |
66436 KB |
Output is correct |
49 |
Correct |
738 ms |
66412 KB |
Output is correct |
50 |
Correct |
734 ms |
66336 KB |
Output is correct |
51 |
Correct |
748 ms |
66448 KB |
Output is correct |
52 |
Correct |
732 ms |
66448 KB |
Output is correct |
53 |
Correct |
735 ms |
66388 KB |
Output is correct |
54 |
Correct |
734 ms |
66380 KB |
Output is correct |
55 |
Correct |
739 ms |
66440 KB |
Output is correct |
56 |
Correct |
740 ms |
66336 KB |
Output is correct |
57 |
Correct |
754 ms |
66412 KB |
Output is correct |
58 |
Correct |
744 ms |
66384 KB |
Output is correct |
59 |
Correct |
741 ms |
66448 KB |
Output is correct |
60 |
Correct |
745 ms |
66364 KB |
Output is correct |
61 |
Correct |
738 ms |
66488 KB |
Output is correct |
62 |
Correct |
731 ms |
66436 KB |
Output is correct |
63 |
Correct |
744 ms |
66368 KB |
Output is correct |
64 |
Correct |
741 ms |
66456 KB |
Output is correct |
65 |
Correct |
750 ms |
66428 KB |
Output is correct |
66 |
Correct |
743 ms |
66432 KB |
Output is correct |
67 |
Correct |
741 ms |
66336 KB |
Output is correct |
68 |
Correct |
738 ms |
66356 KB |
Output is correct |
69 |
Correct |
733 ms |
66352 KB |
Output is correct |
70 |
Correct |
747 ms |
66416 KB |
Output is correct |
71 |
Correct |
744 ms |
66448 KB |
Output is correct |
72 |
Correct |
740 ms |
66448 KB |
Output is correct |
73 |
Correct |
760 ms |
66388 KB |
Output is correct |
74 |
Correct |
751 ms |
66324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |