#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
using ll = long long;
struct Point {
int x, y, w;
Point(int x = 0, int y = 0, int w = 0) : x(x), y(y), w(w) {}
bool operator < (const Point &p) const {
return x < p.x || (x == p.x && y < p.y);
}
Point operator - (const Point &p) const {
return Point(x - p.x, y - p.y);
}
ll cross(const Point &p) const {
return (ll) x * p.y - (ll) y * p.x;
}
};
int n;
Point a[N];
int pos[N];
ll ccw(pair<int, int> u, pair<int, int> v) {
Point p = a[u.second] - a[u.first];
Point q = a[v.second] - a[v.first];
return p.cross(q);
}
struct State {
ll sum, pref, suf, val;
State(int x = 0) {
sum = (ll) x;
pref = suf = val = (ll) max(x, 0);
};
friend State operator + (const State &l, const State &r) {
State ans;
ans.sum = l.sum + r.sum;
ans.pref = max(l.pref, l.sum + r.pref);
ans.suf = max(r.suf, r.sum + l.suf);
ans.val = max({l.val, r.val, l.suf + r.pref});
return ans;
}
};
State t[N << 2];
#define mid ((l + r) >> 1)
void modify(int v, int l, int r, int pos, int val) {
if (l == r) {
t[v] = State(val);
return;
}
if (pos <= mid) {
modify(v << 1, l, mid, pos, val);
} else {
modify(v << 1 | 1, mid + 1, r, pos, val);
}
t[v] = t[v << 1] + t[v << 1 | 1];
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i].x >> a[i].y >> a[i].w;
}
sort(a + 1, a + n + 1);
vector<pair<int, int>> vals;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
vals.emplace_back(i, j);
}
}
sort(vals.begin(), vals.end(), [&](pair<int, int> u, pair<int, int> v) {
ll cur = ccw(u, v);
if (cur) {
return cur < 0;
} else {
return u < v;
}
});
for (int i = 1; i <= n; ++i) {
pos[i] = i;
modify(1, 1, n, i, a[i].w);
}
ll ans = t[1].val;
for (int i = 0; i < (int) vals.size(); ++i) {
vector<pair<int, int>> sw(1, vals[i]);
while (i + 1 < (int) vals.size() && !ccw(vals[i], vals[i + 1])) {
sw.emplace_back(vals[++i]);
}
for (auto p : sw) {
int u, v;
tie(u, v) = p;
swap(pos[u], pos[v]);
modify(1, 1, n, pos[u], a[u].w);
modify(1, 1, n, pos[v], a[v].w);
}
ans = max(ans, t[1].val);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
896 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
3 ms |
640 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
4 ms |
768 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
768 KB |
Output is correct |
25 |
Correct |
4 ms |
768 KB |
Output is correct |
26 |
Correct |
4 ms |
768 KB |
Output is correct |
27 |
Correct |
4 ms |
768 KB |
Output is correct |
28 |
Correct |
4 ms |
768 KB |
Output is correct |
29 |
Correct |
4 ms |
768 KB |
Output is correct |
30 |
Correct |
4 ms |
768 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
896 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
3 ms |
640 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
4 ms |
768 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
768 KB |
Output is correct |
25 |
Correct |
4 ms |
768 KB |
Output is correct |
26 |
Correct |
4 ms |
768 KB |
Output is correct |
27 |
Correct |
4 ms |
768 KB |
Output is correct |
28 |
Correct |
4 ms |
768 KB |
Output is correct |
29 |
Correct |
4 ms |
768 KB |
Output is correct |
30 |
Correct |
4 ms |
768 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
33 |
Correct |
1071 ms |
17260 KB |
Output is correct |
34 |
Correct |
1170 ms |
17224 KB |
Output is correct |
35 |
Correct |
1039 ms |
17260 KB |
Output is correct |
36 |
Correct |
1134 ms |
17320 KB |
Output is correct |
37 |
Correct |
1097 ms |
17236 KB |
Output is correct |
38 |
Correct |
1048 ms |
17252 KB |
Output is correct |
39 |
Correct |
1070 ms |
17260 KB |
Output is correct |
40 |
Correct |
1061 ms |
17260 KB |
Output is correct |
41 |
Correct |
1074 ms |
17260 KB |
Output is correct |
42 |
Correct |
1032 ms |
17260 KB |
Output is correct |
43 |
Correct |
1046 ms |
17304 KB |
Output is correct |
44 |
Correct |
1004 ms |
17260 KB |
Output is correct |
45 |
Correct |
1014 ms |
17260 KB |
Output is correct |
46 |
Correct |
1045 ms |
17248 KB |
Output is correct |
47 |
Correct |
1040 ms |
17284 KB |
Output is correct |
48 |
Correct |
1018 ms |
17252 KB |
Output is correct |
49 |
Correct |
1018 ms |
17260 KB |
Output is correct |
50 |
Correct |
1032 ms |
17260 KB |
Output is correct |
51 |
Correct |
1049 ms |
17260 KB |
Output is correct |
52 |
Correct |
1071 ms |
17252 KB |
Output is correct |
53 |
Correct |
1048 ms |
17260 KB |
Output is correct |
54 |
Correct |
1053 ms |
17260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
896 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
3 ms |
640 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
4 ms |
768 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
768 KB |
Output is correct |
25 |
Correct |
4 ms |
768 KB |
Output is correct |
26 |
Correct |
4 ms |
768 KB |
Output is correct |
27 |
Correct |
4 ms |
768 KB |
Output is correct |
28 |
Correct |
4 ms |
768 KB |
Output is correct |
29 |
Correct |
4 ms |
768 KB |
Output is correct |
30 |
Correct |
4 ms |
768 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
33 |
Correct |
1071 ms |
17260 KB |
Output is correct |
34 |
Correct |
1170 ms |
17224 KB |
Output is correct |
35 |
Correct |
1039 ms |
17260 KB |
Output is correct |
36 |
Correct |
1134 ms |
17320 KB |
Output is correct |
37 |
Correct |
1097 ms |
17236 KB |
Output is correct |
38 |
Correct |
1048 ms |
17252 KB |
Output is correct |
39 |
Correct |
1070 ms |
17260 KB |
Output is correct |
40 |
Correct |
1061 ms |
17260 KB |
Output is correct |
41 |
Correct |
1074 ms |
17260 KB |
Output is correct |
42 |
Correct |
1032 ms |
17260 KB |
Output is correct |
43 |
Correct |
1046 ms |
17304 KB |
Output is correct |
44 |
Correct |
1004 ms |
17260 KB |
Output is correct |
45 |
Correct |
1014 ms |
17260 KB |
Output is correct |
46 |
Correct |
1045 ms |
17248 KB |
Output is correct |
47 |
Correct |
1040 ms |
17284 KB |
Output is correct |
48 |
Correct |
1018 ms |
17252 KB |
Output is correct |
49 |
Correct |
1018 ms |
17260 KB |
Output is correct |
50 |
Correct |
1032 ms |
17260 KB |
Output is correct |
51 |
Correct |
1049 ms |
17260 KB |
Output is correct |
52 |
Correct |
1071 ms |
17252 KB |
Output is correct |
53 |
Correct |
1048 ms |
17260 KB |
Output is correct |
54 |
Correct |
1053 ms |
17260 KB |
Output is correct |
55 |
Correct |
1086 ms |
17248 KB |
Output is correct |
56 |
Correct |
1043 ms |
17260 KB |
Output is correct |
57 |
Correct |
1078 ms |
17256 KB |
Output is correct |
58 |
Correct |
1147 ms |
17248 KB |
Output is correct |
59 |
Correct |
1033 ms |
17252 KB |
Output is correct |
60 |
Correct |
1028 ms |
17252 KB |
Output is correct |
61 |
Correct |
1014 ms |
17260 KB |
Output is correct |
62 |
Correct |
1104 ms |
17252 KB |
Output is correct |
63 |
Correct |
1049 ms |
17248 KB |
Output is correct |
64 |
Correct |
1042 ms |
17260 KB |
Output is correct |
65 |
Correct |
1137 ms |
17260 KB |
Output is correct |
66 |
Correct |
1040 ms |
17260 KB |
Output is correct |
67 |
Correct |
1047 ms |
17248 KB |
Output is correct |
68 |
Correct |
1044 ms |
17252 KB |
Output is correct |
69 |
Correct |
1031 ms |
17260 KB |
Output is correct |
70 |
Correct |
1033 ms |
17260 KB |
Output is correct |
71 |
Correct |
1031 ms |
17388 KB |
Output is correct |
72 |
Correct |
1048 ms |
17260 KB |
Output is correct |
73 |
Correct |
1056 ms |
17260 KB |
Output is correct |
74 |
Correct |
1065 ms |
17296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
768 KB |
Output is correct |
3 |
Correct |
4 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
768 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
4 ms |
768 KB |
Output is correct |
19 |
Correct |
4 ms |
768 KB |
Output is correct |
20 |
Correct |
4 ms |
896 KB |
Output is correct |
21 |
Correct |
4 ms |
768 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
4 ms |
768 KB |
Output is correct |
25 |
Correct |
4 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
640 KB |
Output is correct |
27 |
Correct |
2 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
640 KB |
Output is correct |
29 |
Correct |
2 ms |
640 KB |
Output is correct |
30 |
Correct |
2 ms |
640 KB |
Output is correct |
31 |
Correct |
2 ms |
768 KB |
Output is correct |
32 |
Correct |
2 ms |
640 KB |
Output is correct |
33 |
Correct |
2 ms |
640 KB |
Output is correct |
34 |
Correct |
3 ms |
640 KB |
Output is correct |
35 |
Correct |
2 ms |
640 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
39 |
Correct |
4 ms |
768 KB |
Output is correct |
40 |
Correct |
4 ms |
768 KB |
Output is correct |
41 |
Correct |
4 ms |
768 KB |
Output is correct |
42 |
Correct |
4 ms |
768 KB |
Output is correct |
43 |
Correct |
4 ms |
768 KB |
Output is correct |
44 |
Correct |
4 ms |
768 KB |
Output is correct |
45 |
Correct |
4 ms |
768 KB |
Output is correct |
46 |
Correct |
4 ms |
768 KB |
Output is correct |
47 |
Correct |
4 ms |
768 KB |
Output is correct |
48 |
Correct |
1071 ms |
17260 KB |
Output is correct |
49 |
Correct |
1170 ms |
17224 KB |
Output is correct |
50 |
Correct |
1039 ms |
17260 KB |
Output is correct |
51 |
Correct |
1134 ms |
17320 KB |
Output is correct |
52 |
Correct |
1097 ms |
17236 KB |
Output is correct |
53 |
Correct |
1048 ms |
17252 KB |
Output is correct |
54 |
Correct |
1070 ms |
17260 KB |
Output is correct |
55 |
Correct |
1061 ms |
17260 KB |
Output is correct |
56 |
Correct |
1074 ms |
17260 KB |
Output is correct |
57 |
Correct |
1032 ms |
17260 KB |
Output is correct |
58 |
Correct |
1046 ms |
17304 KB |
Output is correct |
59 |
Correct |
1004 ms |
17260 KB |
Output is correct |
60 |
Correct |
1014 ms |
17260 KB |
Output is correct |
61 |
Correct |
1045 ms |
17248 KB |
Output is correct |
62 |
Correct |
1040 ms |
17284 KB |
Output is correct |
63 |
Correct |
1018 ms |
17252 KB |
Output is correct |
64 |
Correct |
1018 ms |
17260 KB |
Output is correct |
65 |
Correct |
1032 ms |
17260 KB |
Output is correct |
66 |
Correct |
1049 ms |
17260 KB |
Output is correct |
67 |
Correct |
1071 ms |
17252 KB |
Output is correct |
68 |
Correct |
1048 ms |
17260 KB |
Output is correct |
69 |
Correct |
1053 ms |
17260 KB |
Output is correct |
70 |
Correct |
1086 ms |
17248 KB |
Output is correct |
71 |
Correct |
1043 ms |
17260 KB |
Output is correct |
72 |
Correct |
1078 ms |
17256 KB |
Output is correct |
73 |
Correct |
1147 ms |
17248 KB |
Output is correct |
74 |
Correct |
1033 ms |
17252 KB |
Output is correct |
75 |
Correct |
1028 ms |
17252 KB |
Output is correct |
76 |
Correct |
1014 ms |
17260 KB |
Output is correct |
77 |
Correct |
1104 ms |
17252 KB |
Output is correct |
78 |
Correct |
1049 ms |
17248 KB |
Output is correct |
79 |
Correct |
1042 ms |
17260 KB |
Output is correct |
80 |
Correct |
1137 ms |
17260 KB |
Output is correct |
81 |
Correct |
1040 ms |
17260 KB |
Output is correct |
82 |
Correct |
1047 ms |
17248 KB |
Output is correct |
83 |
Correct |
1044 ms |
17252 KB |
Output is correct |
84 |
Correct |
1031 ms |
17260 KB |
Output is correct |
85 |
Correct |
1033 ms |
17260 KB |
Output is correct |
86 |
Correct |
1031 ms |
17388 KB |
Output is correct |
87 |
Correct |
1048 ms |
17260 KB |
Output is correct |
88 |
Correct |
1056 ms |
17260 KB |
Output is correct |
89 |
Correct |
1065 ms |
17296 KB |
Output is correct |
90 |
Correct |
1061 ms |
17260 KB |
Output is correct |
91 |
Correct |
1049 ms |
17252 KB |
Output is correct |
92 |
Correct |
1037 ms |
17260 KB |
Output is correct |
93 |
Correct |
1043 ms |
17252 KB |
Output is correct |
94 |
Correct |
1057 ms |
17260 KB |
Output is correct |
95 |
Correct |
1037 ms |
17252 KB |
Output is correct |
96 |
Correct |
1247 ms |
17252 KB |
Output is correct |
97 |
Correct |
1030 ms |
17260 KB |
Output is correct |
98 |
Correct |
1048 ms |
17252 KB |
Output is correct |
99 |
Correct |
1080 ms |
17252 KB |
Output is correct |
100 |
Correct |
880 ms |
32448 KB |
Output is correct |
101 |
Correct |
855 ms |
32480 KB |
Output is correct |
102 |
Correct |
850 ms |
32320 KB |
Output is correct |
103 |
Correct |
870 ms |
32448 KB |
Output is correct |
104 |
Correct |
911 ms |
32448 KB |
Output is correct |
105 |
Correct |
914 ms |
29888 KB |
Output is correct |
106 |
Correct |
930 ms |
29932 KB |
Output is correct |
107 |
Correct |
925 ms |
29888 KB |
Output is correct |
108 |
Correct |
935 ms |
30016 KB |
Output is correct |
109 |
Correct |
905 ms |
29804 KB |
Output is correct |
110 |
Correct |
911 ms |
17260 KB |
Output is correct |
111 |
Correct |
921 ms |
17248 KB |
Output is correct |
112 |
Correct |
964 ms |
17260 KB |
Output is correct |
113 |
Correct |
947 ms |
17260 KB |
Output is correct |
114 |
Correct |
926 ms |
17260 KB |
Output is correct |
115 |
Correct |
936 ms |
17248 KB |
Output is correct |
116 |
Correct |
949 ms |
17260 KB |
Output is correct |
117 |
Correct |
937 ms |
17244 KB |
Output is correct |
118 |
Correct |
965 ms |
17260 KB |
Output is correct |
119 |
Correct |
937 ms |
17252 KB |
Output is correct |
120 |
Correct |
2 ms |
640 KB |
Output is correct |
121 |
Correct |
2 ms |
640 KB |
Output is correct |
122 |
Correct |
1039 ms |
17260 KB |
Output is correct |
123 |
Correct |
1035 ms |
17252 KB |
Output is correct |
124 |
Correct |
1032 ms |
17252 KB |
Output is correct |
125 |
Correct |
1061 ms |
17244 KB |
Output is correct |
126 |
Correct |
1068 ms |
17252 KB |
Output is correct |
127 |
Correct |
1063 ms |
17260 KB |
Output is correct |
128 |
Correct |
1065 ms |
17260 KB |
Output is correct |
129 |
Correct |
1062 ms |
17260 KB |
Output is correct |
130 |
Correct |
1081 ms |
17260 KB |
Output is correct |
131 |
Correct |
1044 ms |
17260 KB |
Output is correct |
132 |
Correct |
1072 ms |
17252 KB |
Output is correct |
133 |
Correct |
1016 ms |
17244 KB |
Output is correct |