#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 11;
using ll = int64_t;
const ll inf = 1e18;
struct S {
ll pref, suff, ans, sum;
S(ll x = 0) : sum{x} { ans = pref = suff = x > 0 ? x : 0; }
S(const S &l, const S &r) : ans{max(l.ans, r.ans)} {
pref = max(l.pref, l.sum + r.pref);
suff = max(l.suff + r.sum, r.suff);
ans = max(ans, l.suff + r.pref);
sum = l.sum + r.sum;
}
} t[N << 1];
int sz = 1;
void update(int p, ll x) { for (t[p += sz] = x; p >>= 1; ) t[p] = {t[p << 1], t[p << 1|1]}; }
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x...) begin(x), end(x)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
using point = complex<ll>;
ll cross(const point &a, const point &b) { return imag(conj(a) * b); }
int w[N], ord[N], pos[N];
point p[N];
vector<int> g[N], line;
bool vis[N];
void dfs(int u) {
vis[u] = 1; line.push_back(u);
for (int v : g[u]) if (!vis[v]) dfs(v);
}
pair<point, pair<int, int>> m[N * N];
vector<int> cur;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n; while (sz < n) sz <<= 1;
rep(i, 0, n) { int x, y; cin >> x >> y >> w[i]; p[i] = {x, y}; ord[i] = i; }
sort(ord, ord + n, [&](int a, int b) {
return pair(imag(p[a]), -real(p[a])) < pair(imag(p[b]), -real(p[b]));
});
rep(i, 0, n) pos[ord[i]] = i;
rep(i, 0, n) update(pos[i], w[i]);
int c = 0;
rep(i, 0, n) {
rep(j, i + 1, n) {
point z = p[i] - p[j];
ll g = gcd(real(z), imag(z));
z = {real(z) / g, imag(z) / g};
if (imag(z) <= 0) z = -z;
m[c++] = {z, {i, j}};
m[c++] = {z, {j, i}};
}
}
sort(m, m + c, [&](auto a, auto b) { return cross(a.first, b.first) > 0; });
ll ans = t[1].ans;
for (int i = 0, j = 0; i < c; i = j) {
while (j < c && m[i].first == m[j].first) ++j;
rep(k, i, j) g[m[k].second.first].push_back(m[k].second.second);
rep(k, i, j) {
if (vis[m[k].second.first]) continue;
line.clear(); dfs(m[k].second.first);
sort(all(line), [&](int x, int y) { return real(p[x]) < real(p[y]);});
int s = line.size();
for (int i = 0; i < s - i - 1; ++i)
swap(pos[line[i]], pos[line[s - i - 1]]);
for (int i : line) update(pos[i], w[i]);
}
ans = max(ans, t[1].ans);
rep(k, i, j) g[m[k].second.first].clear(), vis[m[k].second.first] = 0;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
896 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
896 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
788 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 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 |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
768 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
27 |
Correct |
3 ms |
768 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
3 ms |
768 KB |
Output is correct |
30 |
Correct |
3 ms |
768 KB |
Output is correct |
31 |
Correct |
3 ms |
768 KB |
Output is correct |
32 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
788 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 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 |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
768 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
27 |
Correct |
3 ms |
768 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
3 ms |
768 KB |
Output is correct |
30 |
Correct |
3 ms |
768 KB |
Output is correct |
31 |
Correct |
3 ms |
768 KB |
Output is correct |
32 |
Correct |
3 ms |
768 KB |
Output is correct |
33 |
Correct |
1478 ms |
94712 KB |
Output is correct |
34 |
Correct |
1459 ms |
94712 KB |
Output is correct |
35 |
Correct |
1456 ms |
94936 KB |
Output is correct |
36 |
Correct |
1484 ms |
94756 KB |
Output is correct |
37 |
Correct |
1479 ms |
94576 KB |
Output is correct |
38 |
Correct |
1452 ms |
94840 KB |
Output is correct |
39 |
Correct |
1454 ms |
94720 KB |
Output is correct |
40 |
Correct |
1469 ms |
94584 KB |
Output is correct |
41 |
Correct |
1444 ms |
94712 KB |
Output is correct |
42 |
Correct |
1497 ms |
94712 KB |
Output is correct |
43 |
Correct |
1427 ms |
94712 KB |
Output is correct |
44 |
Correct |
1379 ms |
94584 KB |
Output is correct |
45 |
Correct |
1378 ms |
94724 KB |
Output is correct |
46 |
Correct |
1419 ms |
94584 KB |
Output is correct |
47 |
Correct |
1416 ms |
94712 KB |
Output is correct |
48 |
Correct |
1427 ms |
94696 KB |
Output is correct |
49 |
Correct |
1417 ms |
94584 KB |
Output is correct |
50 |
Correct |
1443 ms |
94704 KB |
Output is correct |
51 |
Correct |
1440 ms |
94592 KB |
Output is correct |
52 |
Correct |
1436 ms |
94700 KB |
Output is correct |
53 |
Correct |
1409 ms |
94840 KB |
Output is correct |
54 |
Correct |
1384 ms |
94740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
788 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 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 |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
768 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
27 |
Correct |
3 ms |
768 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
3 ms |
768 KB |
Output is correct |
30 |
Correct |
3 ms |
768 KB |
Output is correct |
31 |
Correct |
3 ms |
768 KB |
Output is correct |
32 |
Correct |
3 ms |
768 KB |
Output is correct |
33 |
Correct |
1478 ms |
94712 KB |
Output is correct |
34 |
Correct |
1459 ms |
94712 KB |
Output is correct |
35 |
Correct |
1456 ms |
94936 KB |
Output is correct |
36 |
Correct |
1484 ms |
94756 KB |
Output is correct |
37 |
Correct |
1479 ms |
94576 KB |
Output is correct |
38 |
Correct |
1452 ms |
94840 KB |
Output is correct |
39 |
Correct |
1454 ms |
94720 KB |
Output is correct |
40 |
Correct |
1469 ms |
94584 KB |
Output is correct |
41 |
Correct |
1444 ms |
94712 KB |
Output is correct |
42 |
Correct |
1497 ms |
94712 KB |
Output is correct |
43 |
Correct |
1427 ms |
94712 KB |
Output is correct |
44 |
Correct |
1379 ms |
94584 KB |
Output is correct |
45 |
Correct |
1378 ms |
94724 KB |
Output is correct |
46 |
Correct |
1419 ms |
94584 KB |
Output is correct |
47 |
Correct |
1416 ms |
94712 KB |
Output is correct |
48 |
Correct |
1427 ms |
94696 KB |
Output is correct |
49 |
Correct |
1417 ms |
94584 KB |
Output is correct |
50 |
Correct |
1443 ms |
94704 KB |
Output is correct |
51 |
Correct |
1440 ms |
94592 KB |
Output is correct |
52 |
Correct |
1436 ms |
94700 KB |
Output is correct |
53 |
Correct |
1409 ms |
94840 KB |
Output is correct |
54 |
Correct |
1384 ms |
94740 KB |
Output is correct |
55 |
Correct |
1434 ms |
94712 KB |
Output is correct |
56 |
Correct |
1475 ms |
94652 KB |
Output is correct |
57 |
Correct |
1559 ms |
94584 KB |
Output is correct |
58 |
Correct |
1448 ms |
94620 KB |
Output is correct |
59 |
Correct |
1479 ms |
94708 KB |
Output is correct |
60 |
Correct |
1463 ms |
94648 KB |
Output is correct |
61 |
Correct |
1432 ms |
94712 KB |
Output is correct |
62 |
Correct |
1481 ms |
94712 KB |
Output is correct |
63 |
Correct |
1547 ms |
94728 KB |
Output is correct |
64 |
Correct |
1630 ms |
94660 KB |
Output is correct |
65 |
Correct |
1488 ms |
94568 KB |
Output is correct |
66 |
Correct |
1476 ms |
94644 KB |
Output is correct |
67 |
Correct |
1494 ms |
94720 KB |
Output is correct |
68 |
Correct |
1498 ms |
94684 KB |
Output is correct |
69 |
Correct |
1505 ms |
94584 KB |
Output is correct |
70 |
Correct |
1459 ms |
94648 KB |
Output is correct |
71 |
Correct |
1534 ms |
94640 KB |
Output is correct |
72 |
Correct |
1473 ms |
94636 KB |
Output is correct |
73 |
Correct |
1482 ms |
94568 KB |
Output is correct |
74 |
Correct |
1491 ms |
94644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
896 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
896 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
4 ms |
768 KB |
Output is correct |
19 |
Correct |
3 ms |
768 KB |
Output is correct |
20 |
Correct |
3 ms |
768 KB |
Output is correct |
21 |
Correct |
3 ms |
788 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
3 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 |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
0 ms |
512 KB |
Output is correct |
28 |
Correct |
0 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
3 ms |
768 KB |
Output is correct |
37 |
Correct |
3 ms |
768 KB |
Output is correct |
38 |
Correct |
3 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 |
3 ms |
768 KB |
Output is correct |
42 |
Correct |
3 ms |
768 KB |
Output is correct |
43 |
Correct |
3 ms |
768 KB |
Output is correct |
44 |
Correct |
3 ms |
768 KB |
Output is correct |
45 |
Correct |
3 ms |
768 KB |
Output is correct |
46 |
Correct |
3 ms |
768 KB |
Output is correct |
47 |
Correct |
3 ms |
768 KB |
Output is correct |
48 |
Correct |
1478 ms |
94712 KB |
Output is correct |
49 |
Correct |
1459 ms |
94712 KB |
Output is correct |
50 |
Correct |
1456 ms |
94936 KB |
Output is correct |
51 |
Correct |
1484 ms |
94756 KB |
Output is correct |
52 |
Correct |
1479 ms |
94576 KB |
Output is correct |
53 |
Correct |
1452 ms |
94840 KB |
Output is correct |
54 |
Correct |
1454 ms |
94720 KB |
Output is correct |
55 |
Correct |
1469 ms |
94584 KB |
Output is correct |
56 |
Correct |
1444 ms |
94712 KB |
Output is correct |
57 |
Correct |
1497 ms |
94712 KB |
Output is correct |
58 |
Correct |
1427 ms |
94712 KB |
Output is correct |
59 |
Correct |
1379 ms |
94584 KB |
Output is correct |
60 |
Correct |
1378 ms |
94724 KB |
Output is correct |
61 |
Correct |
1419 ms |
94584 KB |
Output is correct |
62 |
Correct |
1416 ms |
94712 KB |
Output is correct |
63 |
Correct |
1427 ms |
94696 KB |
Output is correct |
64 |
Correct |
1417 ms |
94584 KB |
Output is correct |
65 |
Correct |
1443 ms |
94704 KB |
Output is correct |
66 |
Correct |
1440 ms |
94592 KB |
Output is correct |
67 |
Correct |
1436 ms |
94700 KB |
Output is correct |
68 |
Correct |
1409 ms |
94840 KB |
Output is correct |
69 |
Correct |
1384 ms |
94740 KB |
Output is correct |
70 |
Correct |
1434 ms |
94712 KB |
Output is correct |
71 |
Correct |
1475 ms |
94652 KB |
Output is correct |
72 |
Correct |
1559 ms |
94584 KB |
Output is correct |
73 |
Correct |
1448 ms |
94620 KB |
Output is correct |
74 |
Correct |
1479 ms |
94708 KB |
Output is correct |
75 |
Correct |
1463 ms |
94648 KB |
Output is correct |
76 |
Correct |
1432 ms |
94712 KB |
Output is correct |
77 |
Correct |
1481 ms |
94712 KB |
Output is correct |
78 |
Correct |
1547 ms |
94728 KB |
Output is correct |
79 |
Correct |
1630 ms |
94660 KB |
Output is correct |
80 |
Correct |
1488 ms |
94568 KB |
Output is correct |
81 |
Correct |
1476 ms |
94644 KB |
Output is correct |
82 |
Correct |
1494 ms |
94720 KB |
Output is correct |
83 |
Correct |
1498 ms |
94684 KB |
Output is correct |
84 |
Correct |
1505 ms |
94584 KB |
Output is correct |
85 |
Correct |
1459 ms |
94648 KB |
Output is correct |
86 |
Correct |
1534 ms |
94640 KB |
Output is correct |
87 |
Correct |
1473 ms |
94636 KB |
Output is correct |
88 |
Correct |
1482 ms |
94568 KB |
Output is correct |
89 |
Correct |
1491 ms |
94644 KB |
Output is correct |
90 |
Correct |
1479 ms |
94648 KB |
Output is correct |
91 |
Correct |
1512 ms |
94716 KB |
Output is correct |
92 |
Correct |
1514 ms |
94584 KB |
Output is correct |
93 |
Correct |
1505 ms |
94636 KB |
Output is correct |
94 |
Correct |
1478 ms |
94700 KB |
Output is correct |
95 |
Correct |
1474 ms |
94700 KB |
Output is correct |
96 |
Correct |
1454 ms |
94584 KB |
Output is correct |
97 |
Correct |
1491 ms |
94652 KB |
Output is correct |
98 |
Correct |
1507 ms |
94636 KB |
Output is correct |
99 |
Correct |
1494 ms |
94640 KB |
Output is correct |
100 |
Incorrect |
845 ms |
103288 KB |
Output isn't correct |
101 |
Halted |
0 ms |
0 KB |
- |