#include <bits/stdc++.h>
using namespace std;
#define int long long
struct point {
int x;
int y;
int w;
bool operator < (point p) {
if(x == p.x) return y > p.y;
return x < p.x;
}
};
struct frac {
int p;
int q;
frac() { }
frac(int _p, int _q) { p = _p; q = _q; }
};
struct node {
long long mx;
long long pref;
long long suff;
long long sum;
};
bool operator < (frac a, frac b) { return a.p * 1LL * b.q < b.p * 1LL * a.q; }
bool operator == (frac a, frac b) { return a.p * 1LL * b.q == a.q * 1LL * b.p; }
bool operator != (frac a, frac b) { return !(a == b); }
const int N = 2010;
int n;
point a[N];
vector<pair<frac, pair<int, int>>> slopes;
int order[N], pos[N];
node st[4 * N];
void update(int index, int l, int r, int x, int val) {
if(l > r || r < x || x < l) return;
if(l == r) {
st[index].mx = st[index].pref = st[index].suff = max(val, 0LL);
st[index].sum = val;
return;
}
int mid = (l + r) / 2;
if(x <= mid) update(2 * index, l, mid, x, val);
else update(2 * index + 1, mid + 1, r, x, val);
st[index].mx = max({st[2 * index].mx, st[2 * index + 1].mx, st[2 * index].suff + st[2 * index + 1].pref});
st[index].pref = max(st[2 * index].pref, st[2 * index].sum + st[2 * index + 1].pref);
st[index].suff = max(st[2 * index + 1].suff, st[2 * index + 1].sum + st[2 * index].suff);
st[index].sum = st[2 * index].sum + st[2 * index + 1].sum;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].w;
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n; j++) {
int sign = 1;
int dx = a[i].x - a[j].x, dy = a[i].y - a[j].y;
if(dx < 0) sign *= -1;
if(dy < 0) sign *= -1;
dx = abs(dx);
dy = abs(dy);
int g = __gcd(dx, dy);
dx /= g;
dy /= g;
if(dx != 0) dy *= sign;
if(a[i] < a[j]) slopes.push_back({frac(dy, dx), {i, j}});
else slopes.push_back({frac(dy, dx), {j, i}});
}
}
sort(slopes.begin(), slopes.end(), [&](pair<frac, pair<int, int>> x, pair<frac, pair<int, int>> y) {
if(x.first == y.first) {
pair<int, int> i = x.second, j = y.second;
if(i.first == j.first) return a[i.second] < a[j.second];
return a[i.first] < a[j.first];
}
return x.first < y.first;
});
for(int i = 1; i <= n; i++) order[i] = i;
sort(order + 1, order + n + 1, [&](int i, int j) {
return a[i] < a[j];
});
for(int i = 1; i <= n; i++) pos[order[i]] = i;
for(int i = 1; i <= n; i++) update(1, 1, n, i, a[order[i]].w);
long long ans = st[1].mx;
pair<frac, pair<int, int>> lst;
lst.first = frac(-1, LLONG_MIN);
for(pair<frac, pair<int, int>> slope : slopes) {
if(slope.first != lst.first) ans = max(ans, st[1].mx);
{
int i = slope.second.first, j = slope.second.second;
if(pos[i] < pos[j]) {
update(1, 1, n, pos[i], a[order[pos[j]]].w);
update(1, 1, n, pos[j], a[order[pos[i]]].w);
swap(order[pos[i]], order[pos[j]]);
swap(pos[i], pos[j]);
}
}
lst = slope;
}
ans = max(ans, st[1].mx);
cout << ans;
return 0;
}
/*
9
1 1 10
0 1 10
1 0 10
1 2 10
2 1 10
2 2 -1
0 2 -1
2 0 -1
0 0 -1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
860 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
1112 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
860 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
1112 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
33 |
Correct |
872 ms |
66472 KB |
Output is correct |
34 |
Correct |
862 ms |
67752 KB |
Output is correct |
35 |
Correct |
863 ms |
66720 KB |
Output is correct |
36 |
Correct |
897 ms |
67492 KB |
Output is correct |
37 |
Correct |
882 ms |
67944 KB |
Output is correct |
38 |
Correct |
867 ms |
66580 KB |
Output is correct |
39 |
Correct |
861 ms |
68008 KB |
Output is correct |
40 |
Correct |
893 ms |
66420 KB |
Output is correct |
41 |
Correct |
865 ms |
66260 KB |
Output is correct |
42 |
Correct |
867 ms |
66336 KB |
Output is correct |
43 |
Correct |
830 ms |
67496 KB |
Output is correct |
44 |
Correct |
841 ms |
66976 KB |
Output is correct |
45 |
Correct |
828 ms |
67240 KB |
Output is correct |
46 |
Correct |
826 ms |
66728 KB |
Output is correct |
47 |
Correct |
840 ms |
67108 KB |
Output is correct |
48 |
Correct |
837 ms |
68004 KB |
Output is correct |
49 |
Correct |
831 ms |
66984 KB |
Output is correct |
50 |
Correct |
845 ms |
66628 KB |
Output is correct |
51 |
Correct |
850 ms |
66472 KB |
Output is correct |
52 |
Correct |
832 ms |
67992 KB |
Output is correct |
53 |
Correct |
843 ms |
67580 KB |
Output is correct |
54 |
Correct |
839 ms |
68104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
860 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
1112 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
2 ms |
860 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
33 |
Correct |
872 ms |
66472 KB |
Output is correct |
34 |
Correct |
862 ms |
67752 KB |
Output is correct |
35 |
Correct |
863 ms |
66720 KB |
Output is correct |
36 |
Correct |
897 ms |
67492 KB |
Output is correct |
37 |
Correct |
882 ms |
67944 KB |
Output is correct |
38 |
Correct |
867 ms |
66580 KB |
Output is correct |
39 |
Correct |
861 ms |
68008 KB |
Output is correct |
40 |
Correct |
893 ms |
66420 KB |
Output is correct |
41 |
Correct |
865 ms |
66260 KB |
Output is correct |
42 |
Correct |
867 ms |
66336 KB |
Output is correct |
43 |
Correct |
830 ms |
67496 KB |
Output is correct |
44 |
Correct |
841 ms |
66976 KB |
Output is correct |
45 |
Correct |
828 ms |
67240 KB |
Output is correct |
46 |
Correct |
826 ms |
66728 KB |
Output is correct |
47 |
Correct |
840 ms |
67108 KB |
Output is correct |
48 |
Correct |
837 ms |
68004 KB |
Output is correct |
49 |
Correct |
831 ms |
66984 KB |
Output is correct |
50 |
Correct |
845 ms |
66628 KB |
Output is correct |
51 |
Correct |
850 ms |
66472 KB |
Output is correct |
52 |
Correct |
832 ms |
67992 KB |
Output is correct |
53 |
Correct |
843 ms |
67580 KB |
Output is correct |
54 |
Correct |
839 ms |
68104 KB |
Output is correct |
55 |
Correct |
868 ms |
67520 KB |
Output is correct |
56 |
Correct |
860 ms |
67284 KB |
Output is correct |
57 |
Correct |
871 ms |
66464 KB |
Output is correct |
58 |
Correct |
866 ms |
66980 KB |
Output is correct |
59 |
Correct |
871 ms |
67240 KB |
Output is correct |
60 |
Correct |
918 ms |
66660 KB |
Output is correct |
61 |
Correct |
892 ms |
66728 KB |
Output is correct |
62 |
Correct |
856 ms |
67496 KB |
Output is correct |
63 |
Correct |
898 ms |
66220 KB |
Output is correct |
64 |
Correct |
858 ms |
67900 KB |
Output is correct |
65 |
Correct |
861 ms |
67792 KB |
Output is correct |
66 |
Correct |
898 ms |
66572 KB |
Output is correct |
67 |
Correct |
849 ms |
67340 KB |
Output is correct |
68 |
Correct |
862 ms |
67080 KB |
Output is correct |
69 |
Correct |
859 ms |
67496 KB |
Output is correct |
70 |
Correct |
853 ms |
66520 KB |
Output is correct |
71 |
Correct |
867 ms |
67092 KB |
Output is correct |
72 |
Correct |
854 ms |
68000 KB |
Output is correct |
73 |
Correct |
853 ms |
67748 KB |
Output is correct |
74 |
Correct |
858 ms |
66776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
860 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
860 KB |
Output is correct |
37 |
Correct |
2 ms |
860 KB |
Output is correct |
38 |
Correct |
2 ms |
1112 KB |
Output is correct |
39 |
Correct |
2 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
2 ms |
860 KB |
Output is correct |
42 |
Correct |
2 ms |
860 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
2 ms |
860 KB |
Output is correct |
45 |
Correct |
2 ms |
860 KB |
Output is correct |
46 |
Correct |
2 ms |
860 KB |
Output is correct |
47 |
Correct |
2 ms |
860 KB |
Output is correct |
48 |
Correct |
872 ms |
66472 KB |
Output is correct |
49 |
Correct |
862 ms |
67752 KB |
Output is correct |
50 |
Correct |
863 ms |
66720 KB |
Output is correct |
51 |
Correct |
897 ms |
67492 KB |
Output is correct |
52 |
Correct |
882 ms |
67944 KB |
Output is correct |
53 |
Correct |
867 ms |
66580 KB |
Output is correct |
54 |
Correct |
861 ms |
68008 KB |
Output is correct |
55 |
Correct |
893 ms |
66420 KB |
Output is correct |
56 |
Correct |
865 ms |
66260 KB |
Output is correct |
57 |
Correct |
867 ms |
66336 KB |
Output is correct |
58 |
Correct |
830 ms |
67496 KB |
Output is correct |
59 |
Correct |
841 ms |
66976 KB |
Output is correct |
60 |
Correct |
828 ms |
67240 KB |
Output is correct |
61 |
Correct |
826 ms |
66728 KB |
Output is correct |
62 |
Correct |
840 ms |
67108 KB |
Output is correct |
63 |
Correct |
837 ms |
68004 KB |
Output is correct |
64 |
Correct |
831 ms |
66984 KB |
Output is correct |
65 |
Correct |
845 ms |
66628 KB |
Output is correct |
66 |
Correct |
850 ms |
66472 KB |
Output is correct |
67 |
Correct |
832 ms |
67992 KB |
Output is correct |
68 |
Correct |
843 ms |
67580 KB |
Output is correct |
69 |
Correct |
839 ms |
68104 KB |
Output is correct |
70 |
Correct |
868 ms |
67520 KB |
Output is correct |
71 |
Correct |
860 ms |
67284 KB |
Output is correct |
72 |
Correct |
871 ms |
66464 KB |
Output is correct |
73 |
Correct |
866 ms |
66980 KB |
Output is correct |
74 |
Correct |
871 ms |
67240 KB |
Output is correct |
75 |
Correct |
918 ms |
66660 KB |
Output is correct |
76 |
Correct |
892 ms |
66728 KB |
Output is correct |
77 |
Correct |
856 ms |
67496 KB |
Output is correct |
78 |
Correct |
898 ms |
66220 KB |
Output is correct |
79 |
Correct |
858 ms |
67900 KB |
Output is correct |
80 |
Correct |
861 ms |
67792 KB |
Output is correct |
81 |
Correct |
898 ms |
66572 KB |
Output is correct |
82 |
Correct |
849 ms |
67340 KB |
Output is correct |
83 |
Correct |
862 ms |
67080 KB |
Output is correct |
84 |
Correct |
859 ms |
67496 KB |
Output is correct |
85 |
Correct |
853 ms |
66520 KB |
Output is correct |
86 |
Correct |
867 ms |
67092 KB |
Output is correct |
87 |
Correct |
854 ms |
68000 KB |
Output is correct |
88 |
Correct |
853 ms |
67748 KB |
Output is correct |
89 |
Correct |
858 ms |
66776 KB |
Output is correct |
90 |
Correct |
865 ms |
66724 KB |
Output is correct |
91 |
Correct |
852 ms |
67072 KB |
Output is correct |
92 |
Correct |
919 ms |
67748 KB |
Output is correct |
93 |
Correct |
861 ms |
66492 KB |
Output is correct |
94 |
Correct |
852 ms |
66720 KB |
Output is correct |
95 |
Correct |
890 ms |
67236 KB |
Output is correct |
96 |
Correct |
891 ms |
66212 KB |
Output is correct |
97 |
Correct |
859 ms |
66216 KB |
Output is correct |
98 |
Correct |
867 ms |
66700 KB |
Output is correct |
99 |
Correct |
885 ms |
67956 KB |
Output is correct |
100 |
Incorrect |
340 ms |
66740 KB |
Output isn't correct |
101 |
Halted |
0 ms |
0 KB |
- |