#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
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); }
struct cmp {
bool operator()(const point &a, const point &b) const { return cross(a, b) > 0; }
};
map<point, vector<pair<int, int>>, cmp> m;
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);
}
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]);
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[z].emplace_back(i, j);
m[z].emplace_back(j, i);
}
}
ll ans = t[1].ans;
for (auto &[_, d] : m) {
for (auto &[u, v] : d) g[u].push_back(v);
for (auto &[_, v] : d) {
if (vis[v]) continue;
line.clear(); dfs(v);
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]);
}
for (auto &[_, v] : d) g[v].clear(), vis[v] = 0;
ans = max(ans, t[1].ans);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11904 KB |
Output is correct |
2 |
Correct |
9 ms |
11904 KB |
Output is correct |
3 |
Correct |
7 ms |
11904 KB |
Output is correct |
4 |
Correct |
7 ms |
11904 KB |
Output is correct |
5 |
Correct |
8 ms |
11904 KB |
Output is correct |
6 |
Correct |
8 ms |
11904 KB |
Output is correct |
7 |
Correct |
7 ms |
11904 KB |
Output is correct |
8 |
Correct |
7 ms |
11904 KB |
Output is correct |
9 |
Correct |
10 ms |
11904 KB |
Output is correct |
10 |
Correct |
9 ms |
11904 KB |
Output is correct |
11 |
Correct |
7 ms |
11648 KB |
Output is correct |
12 |
Correct |
7 ms |
11648 KB |
Output is correct |
13 |
Correct |
7 ms |
11648 KB |
Output is correct |
14 |
Correct |
7 ms |
11648 KB |
Output is correct |
15 |
Correct |
7 ms |
11648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12160 KB |
Output is correct |
2 |
Correct |
11 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
12160 KB |
Output is correct |
4 |
Correct |
14 ms |
12160 KB |
Output is correct |
5 |
Correct |
11 ms |
12160 KB |
Output is correct |
6 |
Correct |
13 ms |
12160 KB |
Output is correct |
7 |
Correct |
12 ms |
12160 KB |
Output is correct |
8 |
Correct |
12 ms |
12160 KB |
Output is correct |
9 |
Correct |
12 ms |
12160 KB |
Output is correct |
10 |
Correct |
12 ms |
12160 KB |
Output is correct |
11 |
Correct |
7 ms |
11648 KB |
Output is correct |
12 |
Correct |
8 ms |
11648 KB |
Output is correct |
13 |
Correct |
8 ms |
11648 KB |
Output is correct |
14 |
Correct |
8 ms |
11648 KB |
Output is correct |
15 |
Correct |
7 ms |
11776 KB |
Output is correct |
16 |
Correct |
8 ms |
11648 KB |
Output is correct |
17 |
Correct |
7 ms |
11648 KB |
Output is correct |
18 |
Correct |
7 ms |
11648 KB |
Output is correct |
19 |
Correct |
7 ms |
11648 KB |
Output is correct |
20 |
Correct |
7 ms |
11648 KB |
Output is correct |
21 |
Correct |
13 ms |
12288 KB |
Output is correct |
22 |
Correct |
11 ms |
12160 KB |
Output is correct |
23 |
Correct |
11 ms |
12160 KB |
Output is correct |
24 |
Correct |
11 ms |
12160 KB |
Output is correct |
25 |
Correct |
13 ms |
12160 KB |
Output is correct |
26 |
Correct |
11 ms |
12160 KB |
Output is correct |
27 |
Correct |
11 ms |
12160 KB |
Output is correct |
28 |
Correct |
11 ms |
12160 KB |
Output is correct |
29 |
Correct |
11 ms |
12160 KB |
Output is correct |
30 |
Correct |
11 ms |
12160 KB |
Output is correct |
31 |
Correct |
11 ms |
12160 KB |
Output is correct |
32 |
Correct |
11 ms |
12160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12160 KB |
Output is correct |
2 |
Correct |
11 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
12160 KB |
Output is correct |
4 |
Correct |
14 ms |
12160 KB |
Output is correct |
5 |
Correct |
11 ms |
12160 KB |
Output is correct |
6 |
Correct |
13 ms |
12160 KB |
Output is correct |
7 |
Correct |
12 ms |
12160 KB |
Output is correct |
8 |
Correct |
12 ms |
12160 KB |
Output is correct |
9 |
Correct |
12 ms |
12160 KB |
Output is correct |
10 |
Correct |
12 ms |
12160 KB |
Output is correct |
11 |
Correct |
7 ms |
11648 KB |
Output is correct |
12 |
Correct |
8 ms |
11648 KB |
Output is correct |
13 |
Correct |
8 ms |
11648 KB |
Output is correct |
14 |
Correct |
8 ms |
11648 KB |
Output is correct |
15 |
Correct |
7 ms |
11776 KB |
Output is correct |
16 |
Correct |
8 ms |
11648 KB |
Output is correct |
17 |
Correct |
7 ms |
11648 KB |
Output is correct |
18 |
Correct |
7 ms |
11648 KB |
Output is correct |
19 |
Correct |
7 ms |
11648 KB |
Output is correct |
20 |
Correct |
7 ms |
11648 KB |
Output is correct |
21 |
Correct |
13 ms |
12288 KB |
Output is correct |
22 |
Correct |
11 ms |
12160 KB |
Output is correct |
23 |
Correct |
11 ms |
12160 KB |
Output is correct |
24 |
Correct |
11 ms |
12160 KB |
Output is correct |
25 |
Correct |
13 ms |
12160 KB |
Output is correct |
26 |
Correct |
11 ms |
12160 KB |
Output is correct |
27 |
Correct |
11 ms |
12160 KB |
Output is correct |
28 |
Correct |
11 ms |
12160 KB |
Output is correct |
29 |
Correct |
11 ms |
12160 KB |
Output is correct |
30 |
Correct |
11 ms |
12160 KB |
Output is correct |
31 |
Correct |
11 ms |
12160 KB |
Output is correct |
32 |
Correct |
11 ms |
12160 KB |
Output is correct |
33 |
Execution timed out |
2087 ms |
154432 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12160 KB |
Output is correct |
2 |
Correct |
11 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
12160 KB |
Output is correct |
4 |
Correct |
14 ms |
12160 KB |
Output is correct |
5 |
Correct |
11 ms |
12160 KB |
Output is correct |
6 |
Correct |
13 ms |
12160 KB |
Output is correct |
7 |
Correct |
12 ms |
12160 KB |
Output is correct |
8 |
Correct |
12 ms |
12160 KB |
Output is correct |
9 |
Correct |
12 ms |
12160 KB |
Output is correct |
10 |
Correct |
12 ms |
12160 KB |
Output is correct |
11 |
Correct |
7 ms |
11648 KB |
Output is correct |
12 |
Correct |
8 ms |
11648 KB |
Output is correct |
13 |
Correct |
8 ms |
11648 KB |
Output is correct |
14 |
Correct |
8 ms |
11648 KB |
Output is correct |
15 |
Correct |
7 ms |
11776 KB |
Output is correct |
16 |
Correct |
8 ms |
11648 KB |
Output is correct |
17 |
Correct |
7 ms |
11648 KB |
Output is correct |
18 |
Correct |
7 ms |
11648 KB |
Output is correct |
19 |
Correct |
7 ms |
11648 KB |
Output is correct |
20 |
Correct |
7 ms |
11648 KB |
Output is correct |
21 |
Correct |
13 ms |
12288 KB |
Output is correct |
22 |
Correct |
11 ms |
12160 KB |
Output is correct |
23 |
Correct |
11 ms |
12160 KB |
Output is correct |
24 |
Correct |
11 ms |
12160 KB |
Output is correct |
25 |
Correct |
13 ms |
12160 KB |
Output is correct |
26 |
Correct |
11 ms |
12160 KB |
Output is correct |
27 |
Correct |
11 ms |
12160 KB |
Output is correct |
28 |
Correct |
11 ms |
12160 KB |
Output is correct |
29 |
Correct |
11 ms |
12160 KB |
Output is correct |
30 |
Correct |
11 ms |
12160 KB |
Output is correct |
31 |
Correct |
11 ms |
12160 KB |
Output is correct |
32 |
Correct |
11 ms |
12160 KB |
Output is correct |
33 |
Execution timed out |
2087 ms |
154432 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11904 KB |
Output is correct |
2 |
Correct |
9 ms |
11904 KB |
Output is correct |
3 |
Correct |
7 ms |
11904 KB |
Output is correct |
4 |
Correct |
7 ms |
11904 KB |
Output is correct |
5 |
Correct |
8 ms |
11904 KB |
Output is correct |
6 |
Correct |
8 ms |
11904 KB |
Output is correct |
7 |
Correct |
7 ms |
11904 KB |
Output is correct |
8 |
Correct |
7 ms |
11904 KB |
Output is correct |
9 |
Correct |
10 ms |
11904 KB |
Output is correct |
10 |
Correct |
9 ms |
11904 KB |
Output is correct |
11 |
Correct |
7 ms |
11648 KB |
Output is correct |
12 |
Correct |
7 ms |
11648 KB |
Output is correct |
13 |
Correct |
7 ms |
11648 KB |
Output is correct |
14 |
Correct |
7 ms |
11648 KB |
Output is correct |
15 |
Correct |
7 ms |
11648 KB |
Output is correct |
16 |
Correct |
11 ms |
12160 KB |
Output is correct |
17 |
Correct |
11 ms |
12160 KB |
Output is correct |
18 |
Correct |
14 ms |
12160 KB |
Output is correct |
19 |
Correct |
14 ms |
12160 KB |
Output is correct |
20 |
Correct |
11 ms |
12160 KB |
Output is correct |
21 |
Correct |
13 ms |
12160 KB |
Output is correct |
22 |
Correct |
12 ms |
12160 KB |
Output is correct |
23 |
Correct |
12 ms |
12160 KB |
Output is correct |
24 |
Correct |
12 ms |
12160 KB |
Output is correct |
25 |
Correct |
12 ms |
12160 KB |
Output is correct |
26 |
Correct |
7 ms |
11648 KB |
Output is correct |
27 |
Correct |
8 ms |
11648 KB |
Output is correct |
28 |
Correct |
8 ms |
11648 KB |
Output is correct |
29 |
Correct |
8 ms |
11648 KB |
Output is correct |
30 |
Correct |
7 ms |
11776 KB |
Output is correct |
31 |
Correct |
8 ms |
11648 KB |
Output is correct |
32 |
Correct |
7 ms |
11648 KB |
Output is correct |
33 |
Correct |
7 ms |
11648 KB |
Output is correct |
34 |
Correct |
7 ms |
11648 KB |
Output is correct |
35 |
Correct |
7 ms |
11648 KB |
Output is correct |
36 |
Correct |
13 ms |
12288 KB |
Output is correct |
37 |
Correct |
11 ms |
12160 KB |
Output is correct |
38 |
Correct |
11 ms |
12160 KB |
Output is correct |
39 |
Correct |
11 ms |
12160 KB |
Output is correct |
40 |
Correct |
13 ms |
12160 KB |
Output is correct |
41 |
Correct |
11 ms |
12160 KB |
Output is correct |
42 |
Correct |
11 ms |
12160 KB |
Output is correct |
43 |
Correct |
11 ms |
12160 KB |
Output is correct |
44 |
Correct |
11 ms |
12160 KB |
Output is correct |
45 |
Correct |
11 ms |
12160 KB |
Output is correct |
46 |
Correct |
11 ms |
12160 KB |
Output is correct |
47 |
Correct |
11 ms |
12160 KB |
Output is correct |
48 |
Execution timed out |
2087 ms |
154432 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |