#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
struct X {
ll l, r, t, b;
X operator+(X B) {
return {max(l, t + B.l), max(B.r, r + B.t), t + B.t, max(max(b, B.b), r + B.l)};
}
} T[8001];
struct Y {
ll x, y, v;
bool operator<(Y B) {
if (x == B.x) return y < B.y;
return x < B.x;
}
} P[2001];
struct Z {
ll x, y;
int u, v;
bool operator<(Z B) {
if (y * B.x == B.y * x) return tie(u, v) < tie(B.u, B.v);
return y * B.x < B.y * x;
}
} S[2000001];
int n, curr[2001];
void B(int N = 1, int l = 1, int r = n) {
if (l == r) {
ll v = max(P[l].v, 0ll);
T[N] = {v, v, P[l].v, v};
} else {
int M = (l + r) / 2;
B(N * 2, l, M);
B(N * 2 + 1, M + 1, r);
T[N] = T[N * 2] + T[N * 2 + 1];
}
}
void U(int o, ll a, int N = 1, int l = 1, int r = n) {
if (l == r) T[N] = {max(a, 0ll), max(a, 0ll), a, max(a, 0ll)};
else {
int M = (l + r) / 2;
if (o > M) U(o, a, N * 2 + 1, M + 1, r);
else U(o, a, N * 2, l, M);
T[N] = T[N * 2] + T[N * 2 + 1];
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
FOR(i, 1, n + 1) {
cin >> P[i].x >> P[i].y >> P[i].v;
curr[i] = i;
}
sort(P + 1, P + n + 1);
int cnt = 0;
FOR(i, 1, n + 1) FOR(j, i + 1, n + 1)
S[cnt++] = {P[j].x - P[i].x, P[j].y - P[i].y, i, j};
sort(S, S + cnt);
B();
ll ans = T[1].b;
FOR(i, 0, cnt) {
U(curr[S[i].u], P[S[i].v].v);
U(curr[S[i].v], P[S[i].u].v);
swap(curr[S[i].u], curr[S[i].v]);
if (i == cnt - 1) ans = max(ans, T[1].b);
else if (S[i].y * S[i + 1].x != S[i + 1].y * S[i].x) ans = max(ans, T[1].b);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
33 |
Correct |
1020 ms |
47524 KB |
Output is correct |
34 |
Correct |
999 ms |
47584 KB |
Output is correct |
35 |
Correct |
1000 ms |
47608 KB |
Output is correct |
36 |
Correct |
1004 ms |
47516 KB |
Output is correct |
37 |
Correct |
1016 ms |
47516 KB |
Output is correct |
38 |
Correct |
997 ms |
47608 KB |
Output is correct |
39 |
Correct |
1016 ms |
47608 KB |
Output is correct |
40 |
Correct |
1002 ms |
47608 KB |
Output is correct |
41 |
Correct |
1010 ms |
47608 KB |
Output is correct |
42 |
Correct |
1002 ms |
47624 KB |
Output is correct |
43 |
Correct |
1018 ms |
47552 KB |
Output is correct |
44 |
Correct |
1000 ms |
47528 KB |
Output is correct |
45 |
Correct |
987 ms |
47608 KB |
Output is correct |
46 |
Correct |
1018 ms |
47608 KB |
Output is correct |
47 |
Correct |
1022 ms |
47520 KB |
Output is correct |
48 |
Correct |
997 ms |
47480 KB |
Output is correct |
49 |
Correct |
1006 ms |
47608 KB |
Output is correct |
50 |
Correct |
1006 ms |
47608 KB |
Output is correct |
51 |
Correct |
1000 ms |
47480 KB |
Output is correct |
52 |
Correct |
1006 ms |
47608 KB |
Output is correct |
53 |
Correct |
1006 ms |
47520 KB |
Output is correct |
54 |
Correct |
995 ms |
47608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
6 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
33 |
Correct |
1020 ms |
47524 KB |
Output is correct |
34 |
Correct |
999 ms |
47584 KB |
Output is correct |
35 |
Correct |
1000 ms |
47608 KB |
Output is correct |
36 |
Correct |
1004 ms |
47516 KB |
Output is correct |
37 |
Correct |
1016 ms |
47516 KB |
Output is correct |
38 |
Correct |
997 ms |
47608 KB |
Output is correct |
39 |
Correct |
1016 ms |
47608 KB |
Output is correct |
40 |
Correct |
1002 ms |
47608 KB |
Output is correct |
41 |
Correct |
1010 ms |
47608 KB |
Output is correct |
42 |
Correct |
1002 ms |
47624 KB |
Output is correct |
43 |
Correct |
1018 ms |
47552 KB |
Output is correct |
44 |
Correct |
1000 ms |
47528 KB |
Output is correct |
45 |
Correct |
987 ms |
47608 KB |
Output is correct |
46 |
Correct |
1018 ms |
47608 KB |
Output is correct |
47 |
Correct |
1022 ms |
47520 KB |
Output is correct |
48 |
Correct |
997 ms |
47480 KB |
Output is correct |
49 |
Correct |
1006 ms |
47608 KB |
Output is correct |
50 |
Correct |
1006 ms |
47608 KB |
Output is correct |
51 |
Correct |
1000 ms |
47480 KB |
Output is correct |
52 |
Correct |
1006 ms |
47608 KB |
Output is correct |
53 |
Correct |
1006 ms |
47520 KB |
Output is correct |
54 |
Correct |
995 ms |
47608 KB |
Output is correct |
55 |
Correct |
998 ms |
47608 KB |
Output is correct |
56 |
Correct |
1004 ms |
47608 KB |
Output is correct |
57 |
Correct |
1018 ms |
47608 KB |
Output is correct |
58 |
Correct |
1006 ms |
47608 KB |
Output is correct |
59 |
Correct |
1016 ms |
47524 KB |
Output is correct |
60 |
Correct |
1018 ms |
47608 KB |
Output is correct |
61 |
Correct |
1002 ms |
47608 KB |
Output is correct |
62 |
Correct |
1029 ms |
47528 KB |
Output is correct |
63 |
Correct |
1008 ms |
47524 KB |
Output is correct |
64 |
Correct |
1034 ms |
47608 KB |
Output is correct |
65 |
Correct |
1014 ms |
47608 KB |
Output is correct |
66 |
Correct |
1008 ms |
47608 KB |
Output is correct |
67 |
Correct |
1018 ms |
47608 KB |
Output is correct |
68 |
Correct |
1022 ms |
47524 KB |
Output is correct |
69 |
Correct |
1006 ms |
47524 KB |
Output is correct |
70 |
Correct |
1006 ms |
47608 KB |
Output is correct |
71 |
Correct |
1004 ms |
47516 KB |
Output is correct |
72 |
Correct |
1014 ms |
47608 KB |
Output is correct |
73 |
Correct |
1018 ms |
47524 KB |
Output is correct |
74 |
Correct |
1002 ms |
47520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
512 KB |
Output is correct |
17 |
Correct |
7 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
6 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
512 KB |
Output is correct |
21 |
Correct |
7 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
512 KB |
Output is correct |
37 |
Correct |
6 ms |
512 KB |
Output is correct |
38 |
Correct |
6 ms |
512 KB |
Output is correct |
39 |
Correct |
6 ms |
512 KB |
Output is correct |
40 |
Correct |
6 ms |
512 KB |
Output is correct |
41 |
Correct |
6 ms |
512 KB |
Output is correct |
42 |
Correct |
6 ms |
512 KB |
Output is correct |
43 |
Correct |
6 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
512 KB |
Output is correct |
45 |
Correct |
6 ms |
512 KB |
Output is correct |
46 |
Correct |
6 ms |
512 KB |
Output is correct |
47 |
Correct |
6 ms |
512 KB |
Output is correct |
48 |
Correct |
1020 ms |
47524 KB |
Output is correct |
49 |
Correct |
999 ms |
47584 KB |
Output is correct |
50 |
Correct |
1000 ms |
47608 KB |
Output is correct |
51 |
Correct |
1004 ms |
47516 KB |
Output is correct |
52 |
Correct |
1016 ms |
47516 KB |
Output is correct |
53 |
Correct |
997 ms |
47608 KB |
Output is correct |
54 |
Correct |
1016 ms |
47608 KB |
Output is correct |
55 |
Correct |
1002 ms |
47608 KB |
Output is correct |
56 |
Correct |
1010 ms |
47608 KB |
Output is correct |
57 |
Correct |
1002 ms |
47624 KB |
Output is correct |
58 |
Correct |
1018 ms |
47552 KB |
Output is correct |
59 |
Correct |
1000 ms |
47528 KB |
Output is correct |
60 |
Correct |
987 ms |
47608 KB |
Output is correct |
61 |
Correct |
1018 ms |
47608 KB |
Output is correct |
62 |
Correct |
1022 ms |
47520 KB |
Output is correct |
63 |
Correct |
997 ms |
47480 KB |
Output is correct |
64 |
Correct |
1006 ms |
47608 KB |
Output is correct |
65 |
Correct |
1006 ms |
47608 KB |
Output is correct |
66 |
Correct |
1000 ms |
47480 KB |
Output is correct |
67 |
Correct |
1006 ms |
47608 KB |
Output is correct |
68 |
Correct |
1006 ms |
47520 KB |
Output is correct |
69 |
Correct |
995 ms |
47608 KB |
Output is correct |
70 |
Correct |
998 ms |
47608 KB |
Output is correct |
71 |
Correct |
1004 ms |
47608 KB |
Output is correct |
72 |
Correct |
1018 ms |
47608 KB |
Output is correct |
73 |
Correct |
1006 ms |
47608 KB |
Output is correct |
74 |
Correct |
1016 ms |
47524 KB |
Output is correct |
75 |
Correct |
1018 ms |
47608 KB |
Output is correct |
76 |
Correct |
1002 ms |
47608 KB |
Output is correct |
77 |
Correct |
1029 ms |
47528 KB |
Output is correct |
78 |
Correct |
1008 ms |
47524 KB |
Output is correct |
79 |
Correct |
1034 ms |
47608 KB |
Output is correct |
80 |
Correct |
1014 ms |
47608 KB |
Output is correct |
81 |
Correct |
1008 ms |
47608 KB |
Output is correct |
82 |
Correct |
1018 ms |
47608 KB |
Output is correct |
83 |
Correct |
1022 ms |
47524 KB |
Output is correct |
84 |
Correct |
1006 ms |
47524 KB |
Output is correct |
85 |
Correct |
1006 ms |
47608 KB |
Output is correct |
86 |
Correct |
1004 ms |
47516 KB |
Output is correct |
87 |
Correct |
1014 ms |
47608 KB |
Output is correct |
88 |
Correct |
1018 ms |
47524 KB |
Output is correct |
89 |
Correct |
1002 ms |
47520 KB |
Output is correct |
90 |
Correct |
1018 ms |
47648 KB |
Output is correct |
91 |
Correct |
1029 ms |
47608 KB |
Output is correct |
92 |
Correct |
1018 ms |
47608 KB |
Output is correct |
93 |
Correct |
1020 ms |
47480 KB |
Output is correct |
94 |
Correct |
1010 ms |
47608 KB |
Output is correct |
95 |
Correct |
1025 ms |
47608 KB |
Output is correct |
96 |
Correct |
997 ms |
47608 KB |
Output is correct |
97 |
Correct |
1012 ms |
47608 KB |
Output is correct |
98 |
Correct |
1018 ms |
47600 KB |
Output is correct |
99 |
Correct |
1014 ms |
47608 KB |
Output is correct |
100 |
Correct |
822 ms |
47608 KB |
Output is correct |
101 |
Correct |
815 ms |
47480 KB |
Output is correct |
102 |
Correct |
817 ms |
47480 KB |
Output is correct |
103 |
Correct |
836 ms |
47612 KB |
Output is correct |
104 |
Correct |
834 ms |
47524 KB |
Output is correct |
105 |
Correct |
895 ms |
47524 KB |
Output is correct |
106 |
Correct |
895 ms |
47608 KB |
Output is correct |
107 |
Correct |
880 ms |
47608 KB |
Output is correct |
108 |
Correct |
870 ms |
47608 KB |
Output is correct |
109 |
Correct |
888 ms |
47520 KB |
Output is correct |
110 |
Correct |
914 ms |
47524 KB |
Output is correct |
111 |
Correct |
916 ms |
47608 KB |
Output is correct |
112 |
Correct |
934 ms |
47520 KB |
Output is correct |
113 |
Correct |
917 ms |
47608 KB |
Output is correct |
114 |
Correct |
985 ms |
47516 KB |
Output is correct |
115 |
Correct |
947 ms |
47532 KB |
Output is correct |
116 |
Correct |
962 ms |
47524 KB |
Output is correct |
117 |
Correct |
972 ms |
47520 KB |
Output is correct |
118 |
Correct |
939 ms |
47612 KB |
Output is correct |
119 |
Correct |
953 ms |
47516 KB |
Output is correct |
120 |
Correct |
5 ms |
384 KB |
Output is correct |
121 |
Correct |
4 ms |
384 KB |
Output is correct |
122 |
Correct |
1037 ms |
47516 KB |
Output is correct |
123 |
Correct |
1020 ms |
47608 KB |
Output is correct |
124 |
Correct |
1027 ms |
47516 KB |
Output is correct |
125 |
Correct |
1029 ms |
47520 KB |
Output is correct |
126 |
Correct |
1043 ms |
47608 KB |
Output is correct |
127 |
Correct |
1020 ms |
47480 KB |
Output is correct |
128 |
Correct |
1024 ms |
47528 KB |
Output is correct |
129 |
Correct |
1010 ms |
47520 KB |
Output is correct |
130 |
Correct |
1049 ms |
47524 KB |
Output is correct |
131 |
Correct |
1029 ms |
47524 KB |
Output is correct |
132 |
Correct |
1029 ms |
47480 KB |
Output is correct |
133 |
Correct |
1008 ms |
47520 KB |
Output is correct |