#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define mid ((l+r) >> 1)
struct point{
ll x, y, w;
bool operator < (const point &o) const{
return tie(x, y) < tie(o.x, o.y);
}
};
struct line{
int i, j;
ll dx, dy;
bool operator < (const line &o) const{
return make_tuple(dy * o.dx, i, j) < make_tuple(o.dy * dx, o.i, o.j);
}
bool operator == (const line &o) const{
return dy * o.dx == o.dy * dx;
}
};
struct node{
ll mx, l, r, s;
node operator + (const node &o) const{
return {max({mx, o.mx, r+o.l}), max(l, s+o.l), max(o.r, o.s+r), s+o.s};
}
} t[8080];
int n;
void update(int id, ll w, int node = 1, int l = 1, int r = n){
if(id < l || r < id) return;
if(l == r){
t[node] = {w, w, w, w};
return;
}
update(id, w, node*2, l, mid), update(id, w, node*2+1, mid+1, r);
t[node] = t[node*2] + t[node*2+1];
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
vector<point> v(n);
for(auto &[x, y, w] : v) cin >> x >> y >> w;
if(n == 1) return cout << max(0ll, v[0].w), 0;
sort(v.begin(), v.end());
vector<int> p(n); iota(p.begin(), p.end(), 0);
for(int i=0;i<n;i++) update(i+1, v[i].w);
vector<line> l;
for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) l.push_back({i, j, v[j].x-v[i].x, v[j].y-v[i].y});
sort(l.begin(), l.end());
int m = l.size();
ll ans = 0;
for(int i=0;i<m;i++){
int j = i;
while(j+1 < m && l[i] == l[j+1]) j++;
for(int k=i;k<=j;k++){
int a = l[k].i, b = l[k].j;
swap(p[a], p[b]), swap(v[p[a]], v[p[b]]);
update(p[a]+1, v[p[a]].w), update(p[b]+1, v[p[b]].w);
}
ans = max(ans, t[1].mx);
i = j;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
584 KB |
Output is correct |
22 |
Correct |
2 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
3 ms |
584 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
584 KB |
Output is correct |
22 |
Correct |
2 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
3 ms |
584 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
997 ms |
49876 KB |
Output is correct |
34 |
Correct |
960 ms |
49944 KB |
Output is correct |
35 |
Correct |
947 ms |
49952 KB |
Output is correct |
36 |
Correct |
974 ms |
49940 KB |
Output is correct |
37 |
Correct |
1030 ms |
49908 KB |
Output is correct |
38 |
Correct |
946 ms |
49948 KB |
Output is correct |
39 |
Correct |
986 ms |
49944 KB |
Output is correct |
40 |
Correct |
996 ms |
49896 KB |
Output is correct |
41 |
Correct |
968 ms |
49828 KB |
Output is correct |
42 |
Correct |
961 ms |
49920 KB |
Output is correct |
43 |
Correct |
981 ms |
49920 KB |
Output is correct |
44 |
Correct |
941 ms |
49960 KB |
Output is correct |
45 |
Correct |
932 ms |
49872 KB |
Output is correct |
46 |
Correct |
1039 ms |
49972 KB |
Output is correct |
47 |
Correct |
969 ms |
49944 KB |
Output is correct |
48 |
Correct |
921 ms |
49944 KB |
Output is correct |
49 |
Correct |
958 ms |
49852 KB |
Output is correct |
50 |
Correct |
964 ms |
49956 KB |
Output is correct |
51 |
Correct |
959 ms |
49916 KB |
Output is correct |
52 |
Correct |
965 ms |
49956 KB |
Output is correct |
53 |
Correct |
967 ms |
49872 KB |
Output is correct |
54 |
Correct |
950 ms |
49900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
584 KB |
Output is correct |
22 |
Correct |
2 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
3 ms |
584 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
997 ms |
49876 KB |
Output is correct |
34 |
Correct |
960 ms |
49944 KB |
Output is correct |
35 |
Correct |
947 ms |
49952 KB |
Output is correct |
36 |
Correct |
974 ms |
49940 KB |
Output is correct |
37 |
Correct |
1030 ms |
49908 KB |
Output is correct |
38 |
Correct |
946 ms |
49948 KB |
Output is correct |
39 |
Correct |
986 ms |
49944 KB |
Output is correct |
40 |
Correct |
996 ms |
49896 KB |
Output is correct |
41 |
Correct |
968 ms |
49828 KB |
Output is correct |
42 |
Correct |
961 ms |
49920 KB |
Output is correct |
43 |
Correct |
981 ms |
49920 KB |
Output is correct |
44 |
Correct |
941 ms |
49960 KB |
Output is correct |
45 |
Correct |
932 ms |
49872 KB |
Output is correct |
46 |
Correct |
1039 ms |
49972 KB |
Output is correct |
47 |
Correct |
969 ms |
49944 KB |
Output is correct |
48 |
Correct |
921 ms |
49944 KB |
Output is correct |
49 |
Correct |
958 ms |
49852 KB |
Output is correct |
50 |
Correct |
964 ms |
49956 KB |
Output is correct |
51 |
Correct |
959 ms |
49916 KB |
Output is correct |
52 |
Correct |
965 ms |
49956 KB |
Output is correct |
53 |
Correct |
967 ms |
49872 KB |
Output is correct |
54 |
Correct |
950 ms |
49900 KB |
Output is correct |
55 |
Correct |
960 ms |
49920 KB |
Output is correct |
56 |
Correct |
992 ms |
49944 KB |
Output is correct |
57 |
Correct |
975 ms |
49920 KB |
Output is correct |
58 |
Correct |
942 ms |
49968 KB |
Output is correct |
59 |
Correct |
970 ms |
49948 KB |
Output is correct |
60 |
Correct |
973 ms |
49944 KB |
Output is correct |
61 |
Correct |
950 ms |
49916 KB |
Output is correct |
62 |
Correct |
1000 ms |
49860 KB |
Output is correct |
63 |
Correct |
1006 ms |
49944 KB |
Output is correct |
64 |
Correct |
1020 ms |
49880 KB |
Output is correct |
65 |
Correct |
1077 ms |
49972 KB |
Output is correct |
66 |
Correct |
1103 ms |
50012 KB |
Output is correct |
67 |
Correct |
1129 ms |
49972 KB |
Output is correct |
68 |
Correct |
1144 ms |
49872 KB |
Output is correct |
69 |
Correct |
1106 ms |
49848 KB |
Output is correct |
70 |
Correct |
1052 ms |
49948 KB |
Output is correct |
71 |
Correct |
1008 ms |
49956 KB |
Output is correct |
72 |
Correct |
997 ms |
49892 KB |
Output is correct |
73 |
Correct |
981 ms |
49944 KB |
Output is correct |
74 |
Correct |
999 ms |
49988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
2 ms |
584 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
2 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
596 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
3 ms |
584 KB |
Output is correct |
46 |
Correct |
3 ms |
596 KB |
Output is correct |
47 |
Correct |
2 ms |
596 KB |
Output is correct |
48 |
Correct |
997 ms |
49876 KB |
Output is correct |
49 |
Correct |
960 ms |
49944 KB |
Output is correct |
50 |
Correct |
947 ms |
49952 KB |
Output is correct |
51 |
Correct |
974 ms |
49940 KB |
Output is correct |
52 |
Correct |
1030 ms |
49908 KB |
Output is correct |
53 |
Correct |
946 ms |
49948 KB |
Output is correct |
54 |
Correct |
986 ms |
49944 KB |
Output is correct |
55 |
Correct |
996 ms |
49896 KB |
Output is correct |
56 |
Correct |
968 ms |
49828 KB |
Output is correct |
57 |
Correct |
961 ms |
49920 KB |
Output is correct |
58 |
Correct |
981 ms |
49920 KB |
Output is correct |
59 |
Correct |
941 ms |
49960 KB |
Output is correct |
60 |
Correct |
932 ms |
49872 KB |
Output is correct |
61 |
Correct |
1039 ms |
49972 KB |
Output is correct |
62 |
Correct |
969 ms |
49944 KB |
Output is correct |
63 |
Correct |
921 ms |
49944 KB |
Output is correct |
64 |
Correct |
958 ms |
49852 KB |
Output is correct |
65 |
Correct |
964 ms |
49956 KB |
Output is correct |
66 |
Correct |
959 ms |
49916 KB |
Output is correct |
67 |
Correct |
965 ms |
49956 KB |
Output is correct |
68 |
Correct |
967 ms |
49872 KB |
Output is correct |
69 |
Correct |
950 ms |
49900 KB |
Output is correct |
70 |
Correct |
960 ms |
49920 KB |
Output is correct |
71 |
Correct |
992 ms |
49944 KB |
Output is correct |
72 |
Correct |
975 ms |
49920 KB |
Output is correct |
73 |
Correct |
942 ms |
49968 KB |
Output is correct |
74 |
Correct |
970 ms |
49948 KB |
Output is correct |
75 |
Correct |
973 ms |
49944 KB |
Output is correct |
76 |
Correct |
950 ms |
49916 KB |
Output is correct |
77 |
Correct |
1000 ms |
49860 KB |
Output is correct |
78 |
Correct |
1006 ms |
49944 KB |
Output is correct |
79 |
Correct |
1020 ms |
49880 KB |
Output is correct |
80 |
Correct |
1077 ms |
49972 KB |
Output is correct |
81 |
Correct |
1103 ms |
50012 KB |
Output is correct |
82 |
Correct |
1129 ms |
49972 KB |
Output is correct |
83 |
Correct |
1144 ms |
49872 KB |
Output is correct |
84 |
Correct |
1106 ms |
49848 KB |
Output is correct |
85 |
Correct |
1052 ms |
49948 KB |
Output is correct |
86 |
Correct |
1008 ms |
49956 KB |
Output is correct |
87 |
Correct |
997 ms |
49892 KB |
Output is correct |
88 |
Correct |
981 ms |
49944 KB |
Output is correct |
89 |
Correct |
999 ms |
49988 KB |
Output is correct |
90 |
Correct |
981 ms |
49944 KB |
Output is correct |
91 |
Correct |
987 ms |
49944 KB |
Output is correct |
92 |
Correct |
989 ms |
49932 KB |
Output is correct |
93 |
Correct |
969 ms |
49980 KB |
Output is correct |
94 |
Correct |
978 ms |
49944 KB |
Output is correct |
95 |
Correct |
977 ms |
49896 KB |
Output is correct |
96 |
Correct |
948 ms |
49944 KB |
Output is correct |
97 |
Correct |
958 ms |
49952 KB |
Output is correct |
98 |
Correct |
1004 ms |
49864 KB |
Output is correct |
99 |
Correct |
997 ms |
49948 KB |
Output is correct |
100 |
Correct |
833 ms |
49944 KB |
Output is correct |
101 |
Correct |
839 ms |
49968 KB |
Output is correct |
102 |
Correct |
826 ms |
49948 KB |
Output is correct |
103 |
Correct |
827 ms |
49848 KB |
Output is correct |
104 |
Correct |
833 ms |
50036 KB |
Output is correct |
105 |
Correct |
875 ms |
49900 KB |
Output is correct |
106 |
Correct |
863 ms |
49956 KB |
Output is correct |
107 |
Correct |
849 ms |
49920 KB |
Output is correct |
108 |
Correct |
864 ms |
49944 KB |
Output is correct |
109 |
Correct |
856 ms |
49944 KB |
Output is correct |
110 |
Correct |
966 ms |
49952 KB |
Output is correct |
111 |
Correct |
953 ms |
49952 KB |
Output is correct |
112 |
Correct |
1018 ms |
49924 KB |
Output is correct |
113 |
Correct |
1010 ms |
49816 KB |
Output is correct |
114 |
Correct |
998 ms |
49868 KB |
Output is correct |
115 |
Correct |
977 ms |
49896 KB |
Output is correct |
116 |
Correct |
1006 ms |
49936 KB |
Output is correct |
117 |
Correct |
955 ms |
49944 KB |
Output is correct |
118 |
Correct |
962 ms |
49944 KB |
Output is correct |
119 |
Correct |
902 ms |
49940 KB |
Output is correct |
120 |
Correct |
1 ms |
212 KB |
Output is correct |
121 |
Correct |
1 ms |
212 KB |
Output is correct |
122 |
Correct |
1020 ms |
49944 KB |
Output is correct |
123 |
Correct |
967 ms |
49916 KB |
Output is correct |
124 |
Correct |
1002 ms |
49868 KB |
Output is correct |
125 |
Correct |
976 ms |
49948 KB |
Output is correct |
126 |
Correct |
994 ms |
49860 KB |
Output is correct |
127 |
Correct |
973 ms |
49992 KB |
Output is correct |
128 |
Correct |
976 ms |
49952 KB |
Output is correct |
129 |
Correct |
972 ms |
49920 KB |
Output is correct |
130 |
Correct |
1000 ms |
49944 KB |
Output is correct |
131 |
Correct |
967 ms |
49972 KB |
Output is correct |
132 |
Correct |
1064 ms |
49948 KB |
Output is correct |
133 |
Correct |
956 ms |
49932 KB |
Output is correct |