#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
using namespace std;
#define ar array
#define ll long long
const int N = 2e3, N_ = 1 << 11;
ar<int, 2> norm(ar<int, 2> a) {
int g = gcd(a[0], a[1]);
a[0] /= g, a[1] /= g;
if (a[1] < 0)
a[0] *= -1, a[1] *= -1;
return a;
}
bool comp(const ar<int, 2>& a, const ar<int, 2>& b) {
return 1LL * a[0] * b[1] < 1LL * b[0] * a[1];
}
ar<ll, 4> operator+(const ar<ll, 4>& u, const ar<ll, 4>& v) {
return {u[0] + v[0], max(u[1], u[0] + v[1]), max(v[2], u[2] + v[0]), max(u[2] + v[1], max(u[3], v[3]))};
}
int n_;
ar<ll, 4> t[N_ * 2];
void update(int i, int w) {
t[i += n_] = {w, max(0, w), max(0, w), max(0, w)};
while (i >>= 1)
t[i] = t[i << 1 | 0] + t[i << 1 | 1];
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
n_ = 1;
while (n_ < n)
n_ <<= 1;
static ar<int, 3> p[N];
for (int i = 0; i < n; i++) {
auto &[x, y, w] = p[i];
cin >> x >> y >> w;
}
sort(p, p + n);
static pair<ar<int, 2>, ar<int, 2>> e[N * (N - 1) / 2];
int m = 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (p[i][0] != p[j][0])
e[m++] = make_pair(norm({p[j][1] - p[i][1], p[j][0] - p[i][0]}), ar<int, 2>{i, j});
stable_sort(e, e + m, [&](const pair<ar<int, 2>, ar<int, 2>>& a, const pair<ar<int, 2>, ar<int, 2>>& b) {
return comp(a.first, b.first);
});
static int o[N];
for (int i = 0; i < n; i++) {
update(i, p[i][2]);
o[i] = i;
}
ll ans = t[1][3];
for (int h = 0; h < m; h++) {
auto [s, ij] = e[h];
auto [i, j] = ij;
swap(o[i], o[j]);
update(o[i], p[i][2]), update(o[j], p[j][2]);
if (h == m - 1 || s != e[h + 1].first)
ans = max(ans, t[1][3]);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
456 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
232 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
456 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
456 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
232 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
456 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
695 ms |
62936 KB |
Output is correct |
34 |
Correct |
688 ms |
62980 KB |
Output is correct |
35 |
Correct |
694 ms |
63052 KB |
Output is correct |
36 |
Correct |
705 ms |
62920 KB |
Output is correct |
37 |
Correct |
712 ms |
63040 KB |
Output is correct |
38 |
Correct |
689 ms |
62936 KB |
Output is correct |
39 |
Correct |
685 ms |
63008 KB |
Output is correct |
40 |
Correct |
697 ms |
62920 KB |
Output is correct |
41 |
Correct |
690 ms |
63000 KB |
Output is correct |
42 |
Correct |
706 ms |
62956 KB |
Output is correct |
43 |
Correct |
651 ms |
62948 KB |
Output is correct |
44 |
Correct |
651 ms |
62992 KB |
Output is correct |
45 |
Correct |
650 ms |
62904 KB |
Output is correct |
46 |
Correct |
656 ms |
62992 KB |
Output is correct |
47 |
Correct |
650 ms |
62908 KB |
Output is correct |
48 |
Correct |
675 ms |
62924 KB |
Output is correct |
49 |
Correct |
671 ms |
62884 KB |
Output is correct |
50 |
Correct |
650 ms |
62980 KB |
Output is correct |
51 |
Correct |
675 ms |
62916 KB |
Output is correct |
52 |
Correct |
654 ms |
62976 KB |
Output is correct |
53 |
Correct |
655 ms |
63068 KB |
Output is correct |
54 |
Correct |
658 ms |
62988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
456 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
232 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
456 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
695 ms |
62936 KB |
Output is correct |
34 |
Correct |
688 ms |
62980 KB |
Output is correct |
35 |
Correct |
694 ms |
63052 KB |
Output is correct |
36 |
Correct |
705 ms |
62920 KB |
Output is correct |
37 |
Correct |
712 ms |
63040 KB |
Output is correct |
38 |
Correct |
689 ms |
62936 KB |
Output is correct |
39 |
Correct |
685 ms |
63008 KB |
Output is correct |
40 |
Correct |
697 ms |
62920 KB |
Output is correct |
41 |
Correct |
690 ms |
63000 KB |
Output is correct |
42 |
Correct |
706 ms |
62956 KB |
Output is correct |
43 |
Correct |
651 ms |
62948 KB |
Output is correct |
44 |
Correct |
651 ms |
62992 KB |
Output is correct |
45 |
Correct |
650 ms |
62904 KB |
Output is correct |
46 |
Correct |
656 ms |
62992 KB |
Output is correct |
47 |
Correct |
650 ms |
62908 KB |
Output is correct |
48 |
Correct |
675 ms |
62924 KB |
Output is correct |
49 |
Correct |
671 ms |
62884 KB |
Output is correct |
50 |
Correct |
650 ms |
62980 KB |
Output is correct |
51 |
Correct |
675 ms |
62916 KB |
Output is correct |
52 |
Correct |
654 ms |
62976 KB |
Output is correct |
53 |
Correct |
655 ms |
63068 KB |
Output is correct |
54 |
Correct |
658 ms |
62988 KB |
Output is correct |
55 |
Correct |
721 ms |
62872 KB |
Output is correct |
56 |
Correct |
690 ms |
62984 KB |
Output is correct |
57 |
Correct |
688 ms |
62924 KB |
Output is correct |
58 |
Correct |
697 ms |
62988 KB |
Output is correct |
59 |
Correct |
693 ms |
62936 KB |
Output is correct |
60 |
Correct |
702 ms |
62932 KB |
Output is correct |
61 |
Correct |
706 ms |
62940 KB |
Output is correct |
62 |
Correct |
697 ms |
62876 KB |
Output is correct |
63 |
Correct |
697 ms |
62964 KB |
Output is correct |
64 |
Correct |
700 ms |
63044 KB |
Output is correct |
65 |
Correct |
715 ms |
62884 KB |
Output is correct |
66 |
Correct |
695 ms |
62872 KB |
Output is correct |
67 |
Correct |
693 ms |
62900 KB |
Output is correct |
68 |
Correct |
674 ms |
62968 KB |
Output is correct |
69 |
Correct |
687 ms |
62848 KB |
Output is correct |
70 |
Correct |
708 ms |
62924 KB |
Output is correct |
71 |
Correct |
700 ms |
62924 KB |
Output is correct |
72 |
Correct |
704 ms |
62904 KB |
Output is correct |
73 |
Correct |
709 ms |
62936 KB |
Output is correct |
74 |
Correct |
687 ms |
62960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
2 ms |
456 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
456 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
232 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
456 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
2 ms |
456 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
2 ms |
468 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
695 ms |
62936 KB |
Output is correct |
49 |
Correct |
688 ms |
62980 KB |
Output is correct |
50 |
Correct |
694 ms |
63052 KB |
Output is correct |
51 |
Correct |
705 ms |
62920 KB |
Output is correct |
52 |
Correct |
712 ms |
63040 KB |
Output is correct |
53 |
Correct |
689 ms |
62936 KB |
Output is correct |
54 |
Correct |
685 ms |
63008 KB |
Output is correct |
55 |
Correct |
697 ms |
62920 KB |
Output is correct |
56 |
Correct |
690 ms |
63000 KB |
Output is correct |
57 |
Correct |
706 ms |
62956 KB |
Output is correct |
58 |
Correct |
651 ms |
62948 KB |
Output is correct |
59 |
Correct |
651 ms |
62992 KB |
Output is correct |
60 |
Correct |
650 ms |
62904 KB |
Output is correct |
61 |
Correct |
656 ms |
62992 KB |
Output is correct |
62 |
Correct |
650 ms |
62908 KB |
Output is correct |
63 |
Correct |
675 ms |
62924 KB |
Output is correct |
64 |
Correct |
671 ms |
62884 KB |
Output is correct |
65 |
Correct |
650 ms |
62980 KB |
Output is correct |
66 |
Correct |
675 ms |
62916 KB |
Output is correct |
67 |
Correct |
654 ms |
62976 KB |
Output is correct |
68 |
Correct |
655 ms |
63068 KB |
Output is correct |
69 |
Correct |
658 ms |
62988 KB |
Output is correct |
70 |
Correct |
721 ms |
62872 KB |
Output is correct |
71 |
Correct |
690 ms |
62984 KB |
Output is correct |
72 |
Correct |
688 ms |
62924 KB |
Output is correct |
73 |
Correct |
697 ms |
62988 KB |
Output is correct |
74 |
Correct |
693 ms |
62936 KB |
Output is correct |
75 |
Correct |
702 ms |
62932 KB |
Output is correct |
76 |
Correct |
706 ms |
62940 KB |
Output is correct |
77 |
Correct |
697 ms |
62876 KB |
Output is correct |
78 |
Correct |
697 ms |
62964 KB |
Output is correct |
79 |
Correct |
700 ms |
63044 KB |
Output is correct |
80 |
Correct |
715 ms |
62884 KB |
Output is correct |
81 |
Correct |
695 ms |
62872 KB |
Output is correct |
82 |
Correct |
693 ms |
62900 KB |
Output is correct |
83 |
Correct |
674 ms |
62968 KB |
Output is correct |
84 |
Correct |
687 ms |
62848 KB |
Output is correct |
85 |
Correct |
708 ms |
62924 KB |
Output is correct |
86 |
Correct |
700 ms |
62924 KB |
Output is correct |
87 |
Correct |
704 ms |
62904 KB |
Output is correct |
88 |
Correct |
709 ms |
62936 KB |
Output is correct |
89 |
Correct |
687 ms |
62960 KB |
Output is correct |
90 |
Correct |
708 ms |
63064 KB |
Output is correct |
91 |
Correct |
726 ms |
62952 KB |
Output is correct |
92 |
Correct |
691 ms |
62924 KB |
Output is correct |
93 |
Correct |
724 ms |
62928 KB |
Output is correct |
94 |
Correct |
713 ms |
62920 KB |
Output is correct |
95 |
Correct |
693 ms |
62888 KB |
Output is correct |
96 |
Correct |
705 ms |
62936 KB |
Output is correct |
97 |
Correct |
708 ms |
62988 KB |
Output is correct |
98 |
Correct |
696 ms |
62924 KB |
Output is correct |
99 |
Correct |
728 ms |
62884 KB |
Output is correct |
100 |
Correct |
227 ms |
31696 KB |
Output is correct |
101 |
Correct |
229 ms |
31620 KB |
Output is correct |
102 |
Correct |
228 ms |
31576 KB |
Output is correct |
103 |
Correct |
228 ms |
31632 KB |
Output is correct |
104 |
Correct |
231 ms |
31680 KB |
Output is correct |
105 |
Correct |
320 ms |
42096 KB |
Output is correct |
106 |
Correct |
333 ms |
42016 KB |
Output is correct |
107 |
Correct |
308 ms |
42080 KB |
Output is correct |
108 |
Correct |
333 ms |
42060 KB |
Output is correct |
109 |
Correct |
309 ms |
42060 KB |
Output is correct |
110 |
Correct |
489 ms |
61920 KB |
Output is correct |
111 |
Correct |
485 ms |
61976 KB |
Output is correct |
112 |
Correct |
479 ms |
61900 KB |
Output is correct |
113 |
Correct |
508 ms |
61948 KB |
Output is correct |
114 |
Correct |
479 ms |
61884 KB |
Output is correct |
115 |
Correct |
483 ms |
62004 KB |
Output is correct |
116 |
Correct |
477 ms |
61884 KB |
Output is correct |
117 |
Correct |
483 ms |
61884 KB |
Output is correct |
118 |
Correct |
486 ms |
61900 KB |
Output is correct |
119 |
Correct |
477 ms |
61900 KB |
Output is correct |
120 |
Correct |
1 ms |
340 KB |
Output is correct |
121 |
Correct |
0 ms |
340 KB |
Output is correct |
122 |
Correct |
583 ms |
62924 KB |
Output is correct |
123 |
Correct |
592 ms |
62924 KB |
Output is correct |
124 |
Correct |
614 ms |
62924 KB |
Output is correct |
125 |
Correct |
577 ms |
62924 KB |
Output is correct |
126 |
Correct |
624 ms |
62968 KB |
Output is correct |
127 |
Correct |
609 ms |
62884 KB |
Output is correct |
128 |
Correct |
616 ms |
62956 KB |
Output is correct |
129 |
Correct |
598 ms |
62920 KB |
Output is correct |
130 |
Correct |
609 ms |
63020 KB |
Output is correct |
131 |
Correct |
605 ms |
62924 KB |
Output is correct |
132 |
Correct |
596 ms |
62924 KB |
Output is correct |
133 |
Correct |
654 ms |
62916 KB |
Output is correct |