//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
struct Frac {
ll p, q;
Frac() {}
Frac(ll p, ll q) : p(p), q(q) {}
bool operator<(const Frac& oth) const {
return p * oth.q < oth.p * q;
}
bool operator!=(const Frac& oth) const {
return make_pair(p, q) != make_pair(oth.p, oth.q);
}
};
struct Info {
ll p = 0ll, s = 0ll, m = 0ll, a = 0ll;
Info() = default;
Info(ll v) {
p = max(0ll, v);
s = max(0ll, v);
m = max(0ll, v);
a = v;
}
};
Info merge(Info& a, Info& b) {
Info ret;
ret.a = a.a + b.a;
ret.p = max(a.p, a.a + b.p);
ret.s = max(b.s, b.a + a.s);
ret.m = max({a.m, b.m, a.s + b.p, ret.p, ret.s});
return ret;
}
const int maxN = 1 << 11;
vector<Info> t(maxN * 4);
int sz;
void upd(int i, int v) {
i += sz;
t[i] = v;
i >>= 1;
while (i) {
t[i] = merge(t[i << 1], t[i << 1 | 1]);
i >>= 1;
}
}
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
sz = 1;
while (sz < n) sz <<= 1;
vector<array<ll, 3>> kek(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> kek[i][j];
}
}
sort(kek.begin(), kek.end());
vector<tuple<Frac, int, int>> ev;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (kek[i][0] == kek[j][0]) continue;
ll p = kek[j][1] - kek[i][1];
ll q = kek[j][0] - kek[i][0];
ll g = __gcd(p, q);
p /= g, q /= g;
if (q < 0) p *= -1, q *= -1;
ev.emplace_back(Frac(p, q), i, j);
}
}
sort(ev.begin(), ev.end());
vector<int> ord(n);
for (int i = 0; i < n; ++i) {
ord[i] = i;
upd(i, kek[i][2]);
}
ll ans = max(0ll, t[1].m);
int m = (int) ev.size();
for (int x = 0; x < m; ++x) {
auto [s, i, j] = ev[x];
swap(ord[i], ord[j]);
upd(ord[i], kek[i][2]);
upd(ord[j], kek[j][2]);
if (x == m - 1 || s != get<0>(ev[x + 1]))
ans = max(ans, t[1].m);
}
cout << ans;
}
/*
*/
Compilation message
bulldozer.cpp: In function 'int main(int32_t, char**)':
bulldozer.cpp:99:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
99 | auto [s, i, j] = ev[x];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
984 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
984 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
984 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
984 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
984 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
3 ms |
1052 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
984 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
984 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
984 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
3 ms |
1052 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
33 |
Correct |
947 ms |
51116 KB |
Output is correct |
34 |
Correct |
941 ms |
51116 KB |
Output is correct |
35 |
Correct |
944 ms |
50636 KB |
Output is correct |
36 |
Correct |
938 ms |
51096 KB |
Output is correct |
37 |
Correct |
944 ms |
51028 KB |
Output is correct |
38 |
Correct |
936 ms |
51900 KB |
Output is correct |
39 |
Correct |
946 ms |
50092 KB |
Output is correct |
40 |
Correct |
942 ms |
50348 KB |
Output is correct |
41 |
Correct |
938 ms |
52152 KB |
Output is correct |
42 |
Correct |
937 ms |
50356 KB |
Output is correct |
43 |
Correct |
906 ms |
50600 KB |
Output is correct |
44 |
Correct |
901 ms |
51252 KB |
Output is correct |
45 |
Correct |
898 ms |
50600 KB |
Output is correct |
46 |
Correct |
915 ms |
52000 KB |
Output is correct |
47 |
Correct |
912 ms |
50956 KB |
Output is correct |
48 |
Correct |
921 ms |
51072 KB |
Output is correct |
49 |
Correct |
932 ms |
51916 KB |
Output is correct |
50 |
Correct |
928 ms |
50612 KB |
Output is correct |
51 |
Correct |
927 ms |
52056 KB |
Output is correct |
52 |
Correct |
925 ms |
50312 KB |
Output is correct |
53 |
Correct |
919 ms |
51168 KB |
Output is correct |
54 |
Correct |
920 ms |
50524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
984 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
984 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
984 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
3 ms |
1052 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
33 |
Correct |
947 ms |
51116 KB |
Output is correct |
34 |
Correct |
941 ms |
51116 KB |
Output is correct |
35 |
Correct |
944 ms |
50636 KB |
Output is correct |
36 |
Correct |
938 ms |
51096 KB |
Output is correct |
37 |
Correct |
944 ms |
51028 KB |
Output is correct |
38 |
Correct |
936 ms |
51900 KB |
Output is correct |
39 |
Correct |
946 ms |
50092 KB |
Output is correct |
40 |
Correct |
942 ms |
50348 KB |
Output is correct |
41 |
Correct |
938 ms |
52152 KB |
Output is correct |
42 |
Correct |
937 ms |
50356 KB |
Output is correct |
43 |
Correct |
906 ms |
50600 KB |
Output is correct |
44 |
Correct |
901 ms |
51252 KB |
Output is correct |
45 |
Correct |
898 ms |
50600 KB |
Output is correct |
46 |
Correct |
915 ms |
52000 KB |
Output is correct |
47 |
Correct |
912 ms |
50956 KB |
Output is correct |
48 |
Correct |
921 ms |
51072 KB |
Output is correct |
49 |
Correct |
932 ms |
51916 KB |
Output is correct |
50 |
Correct |
928 ms |
50612 KB |
Output is correct |
51 |
Correct |
927 ms |
52056 KB |
Output is correct |
52 |
Correct |
925 ms |
50312 KB |
Output is correct |
53 |
Correct |
919 ms |
51168 KB |
Output is correct |
54 |
Correct |
920 ms |
50524 KB |
Output is correct |
55 |
Correct |
951 ms |
50980 KB |
Output is correct |
56 |
Correct |
956 ms |
51516 KB |
Output is correct |
57 |
Correct |
943 ms |
51108 KB |
Output is correct |
58 |
Correct |
938 ms |
50348 KB |
Output is correct |
59 |
Correct |
940 ms |
51616 KB |
Output is correct |
60 |
Correct |
946 ms |
50276 KB |
Output is correct |
61 |
Correct |
942 ms |
50604 KB |
Output is correct |
62 |
Correct |
947 ms |
52172 KB |
Output is correct |
63 |
Correct |
945 ms |
51620 KB |
Output is correct |
64 |
Correct |
940 ms |
50860 KB |
Output is correct |
65 |
Correct |
941 ms |
52064 KB |
Output is correct |
66 |
Correct |
938 ms |
50860 KB |
Output is correct |
67 |
Correct |
950 ms |
50788 KB |
Output is correct |
68 |
Correct |
947 ms |
51628 KB |
Output is correct |
69 |
Correct |
939 ms |
51004 KB |
Output is correct |
70 |
Correct |
944 ms |
50896 KB |
Output is correct |
71 |
Correct |
939 ms |
51876 KB |
Output is correct |
72 |
Correct |
943 ms |
50860 KB |
Output is correct |
73 |
Correct |
940 ms |
52136 KB |
Output is correct |
74 |
Correct |
941 ms |
50092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
856 KB |
Output is correct |
3 |
Correct |
2 ms |
984 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
984 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
1112 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
984 KB |
Output is correct |
24 |
Correct |
2 ms |
1112 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
1 ms |
856 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
0 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
0 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
984 KB |
Output is correct |
37 |
Correct |
2 ms |
860 KB |
Output is correct |
38 |
Correct |
2 ms |
860 KB |
Output is correct |
39 |
Correct |
2 ms |
860 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
2 ms |
860 KB |
Output is correct |
42 |
Correct |
2 ms |
860 KB |
Output is correct |
43 |
Correct |
2 ms |
984 KB |
Output is correct |
44 |
Correct |
2 ms |
860 KB |
Output is correct |
45 |
Correct |
3 ms |
1052 KB |
Output is correct |
46 |
Correct |
2 ms |
860 KB |
Output is correct |
47 |
Correct |
2 ms |
860 KB |
Output is correct |
48 |
Correct |
947 ms |
51116 KB |
Output is correct |
49 |
Correct |
941 ms |
51116 KB |
Output is correct |
50 |
Correct |
944 ms |
50636 KB |
Output is correct |
51 |
Correct |
938 ms |
51096 KB |
Output is correct |
52 |
Correct |
944 ms |
51028 KB |
Output is correct |
53 |
Correct |
936 ms |
51900 KB |
Output is correct |
54 |
Correct |
946 ms |
50092 KB |
Output is correct |
55 |
Correct |
942 ms |
50348 KB |
Output is correct |
56 |
Correct |
938 ms |
52152 KB |
Output is correct |
57 |
Correct |
937 ms |
50356 KB |
Output is correct |
58 |
Correct |
906 ms |
50600 KB |
Output is correct |
59 |
Correct |
901 ms |
51252 KB |
Output is correct |
60 |
Correct |
898 ms |
50600 KB |
Output is correct |
61 |
Correct |
915 ms |
52000 KB |
Output is correct |
62 |
Correct |
912 ms |
50956 KB |
Output is correct |
63 |
Correct |
921 ms |
51072 KB |
Output is correct |
64 |
Correct |
932 ms |
51916 KB |
Output is correct |
65 |
Correct |
928 ms |
50612 KB |
Output is correct |
66 |
Correct |
927 ms |
52056 KB |
Output is correct |
67 |
Correct |
925 ms |
50312 KB |
Output is correct |
68 |
Correct |
919 ms |
51168 KB |
Output is correct |
69 |
Correct |
920 ms |
50524 KB |
Output is correct |
70 |
Correct |
951 ms |
50980 KB |
Output is correct |
71 |
Correct |
956 ms |
51516 KB |
Output is correct |
72 |
Correct |
943 ms |
51108 KB |
Output is correct |
73 |
Correct |
938 ms |
50348 KB |
Output is correct |
74 |
Correct |
940 ms |
51616 KB |
Output is correct |
75 |
Correct |
946 ms |
50276 KB |
Output is correct |
76 |
Correct |
942 ms |
50604 KB |
Output is correct |
77 |
Correct |
947 ms |
52172 KB |
Output is correct |
78 |
Correct |
945 ms |
51620 KB |
Output is correct |
79 |
Correct |
940 ms |
50860 KB |
Output is correct |
80 |
Correct |
941 ms |
52064 KB |
Output is correct |
81 |
Correct |
938 ms |
50860 KB |
Output is correct |
82 |
Correct |
950 ms |
50788 KB |
Output is correct |
83 |
Correct |
947 ms |
51628 KB |
Output is correct |
84 |
Correct |
939 ms |
51004 KB |
Output is correct |
85 |
Correct |
944 ms |
50896 KB |
Output is correct |
86 |
Correct |
939 ms |
51876 KB |
Output is correct |
87 |
Correct |
943 ms |
50860 KB |
Output is correct |
88 |
Correct |
940 ms |
52136 KB |
Output is correct |
89 |
Correct |
941 ms |
50092 KB |
Output is correct |
90 |
Correct |
950 ms |
51900 KB |
Output is correct |
91 |
Correct |
937 ms |
50344 KB |
Output is correct |
92 |
Correct |
946 ms |
50236 KB |
Output is correct |
93 |
Correct |
940 ms |
50092 KB |
Output is correct |
94 |
Correct |
940 ms |
50596 KB |
Output is correct |
95 |
Correct |
945 ms |
51768 KB |
Output is correct |
96 |
Correct |
942 ms |
51092 KB |
Output is correct |
97 |
Correct |
945 ms |
50576 KB |
Output is correct |
98 |
Correct |
943 ms |
51880 KB |
Output is correct |
99 |
Correct |
941 ms |
50600 KB |
Output is correct |
100 |
Correct |
367 ms |
27380 KB |
Output is correct |
101 |
Correct |
366 ms |
25796 KB |
Output is correct |
102 |
Correct |
363 ms |
25980 KB |
Output is correct |
103 |
Correct |
368 ms |
27068 KB |
Output is correct |
104 |
Correct |
366 ms |
26808 KB |
Output is correct |
105 |
Correct |
496 ms |
50868 KB |
Output is correct |
106 |
Correct |
497 ms |
51716 KB |
Output is correct |
107 |
Correct |
497 ms |
52152 KB |
Output is correct |
108 |
Correct |
496 ms |
50860 KB |
Output is correct |
109 |
Correct |
496 ms |
51388 KB |
Output is correct |
110 |
Correct |
839 ms |
51080 KB |
Output is correct |
111 |
Correct |
834 ms |
51128 KB |
Output is correct |
112 |
Correct |
839 ms |
51920 KB |
Output is correct |
113 |
Correct |
836 ms |
50308 KB |
Output is correct |
114 |
Correct |
840 ms |
51432 KB |
Output is correct |
115 |
Correct |
843 ms |
50608 KB |
Output is correct |
116 |
Correct |
841 ms |
50860 KB |
Output is correct |
117 |
Correct |
841 ms |
51488 KB |
Output is correct |
118 |
Correct |
840 ms |
50096 KB |
Output is correct |
119 |
Correct |
850 ms |
51200 KB |
Output is correct |
120 |
Correct |
1 ms |
604 KB |
Output is correct |
121 |
Correct |
0 ms |
604 KB |
Output is correct |
122 |
Correct |
854 ms |
51232 KB |
Output is correct |
123 |
Correct |
845 ms |
51352 KB |
Output is correct |
124 |
Correct |
846 ms |
51076 KB |
Output is correct |
125 |
Correct |
847 ms |
51928 KB |
Output is correct |
126 |
Correct |
857 ms |
51108 KB |
Output is correct |
127 |
Correct |
843 ms |
50296 KB |
Output is correct |
128 |
Correct |
855 ms |
50856 KB |
Output is correct |
129 |
Correct |
856 ms |
52132 KB |
Output is correct |
130 |
Correct |
847 ms |
51952 KB |
Output is correct |
131 |
Correct |
853 ms |
50200 KB |
Output is correct |
132 |
Correct |
872 ms |
51180 KB |
Output is correct |
133 |
Correct |
848 ms |
50880 KB |
Output is correct |