#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 3e5 + 10;
struct segtree{
vector <int> seg;
void ass(int n) {
seg.assign(n * 4 + 100, 0);
}
void upd(int id, int l, int r, int p, int v) {
if (l > p || r < p)
return;
seg[id] = max(seg[id], v);
if (l == r)
return;
int m = (l + r) / 2;
upd(id * 2, l, m, p, v);
upd(id * 2 + 1, m + 1, r, p, v);
}
int get(int id, int l, int r, int u, int v) {
if (r < u || l > v || u > v)
return 0;
if (l >= u && r <= v)
return seg[id];
int m = (l + r) / 2;
return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}
};
segtree s1, s2;
map <int, int> mp1, mp2;
pair <int, int> best;
int n, sz;
void add(int u, int v) {
int se = s1.get(1, 1, sz, 1, mp1[u] - 1);
if (se > v) {
best = max(best, {u, se});
}
int fi = s2.get(1, 1, sz, 1, mp2[v] - 1);
if (fi > u) {
best = max(best, {fi, v});
}
s1.upd(1, 1, sz, mp1[u], v);
s2.upd(1, 1, sz, mp2[v], u);
}
ll solve() {
best.f = best.s = 0;
cin >> n;
sz = n + 10;
s1.ass(n + 10);
s2.ass(n + 10);
vector < vector <int>> v(n);
for (auto &x : v) {
x.resize(3);
cin >> x[0] >> x[1] >> x[2];
mp1[x[1]];
mp2[x[2]];
}
int t1 = 1, t2 = 1;
for (auto &x : mp1) {
x.s = t1++;
}
for (auto &x : mp2) {
x.s = t2++;
}
sort(all(v));
int j = 0, ans = -1;
for (int i = 0; i < n; i++) {
while (v[j][0] < v[i][0]) {
add(v[j][1], v[j][2]);
j++;
}
if (best.f > v[i][1] && best.s > v[i][2]) {
ans = max(ans, best.f + best.s + v[i][0]);
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
cout << solve() << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
1292 KB |
Output is correct |
27 |
Correct |
6 ms |
1116 KB |
Output is correct |
28 |
Correct |
5 ms |
1116 KB |
Output is correct |
29 |
Correct |
5 ms |
860 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
5 ms |
860 KB |
Output is correct |
32 |
Correct |
5 ms |
872 KB |
Output is correct |
33 |
Correct |
3 ms |
860 KB |
Output is correct |
34 |
Correct |
5 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
980 KB |
Output is correct |
38 |
Correct |
4 ms |
856 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
74 ms |
13136 KB |
Output is correct |
12 |
Correct |
55 ms |
9160 KB |
Output is correct |
13 |
Correct |
47 ms |
11100 KB |
Output is correct |
14 |
Correct |
74 ms |
13372 KB |
Output is correct |
15 |
Correct |
53 ms |
13368 KB |
Output is correct |
16 |
Correct |
36 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
74 ms |
13136 KB |
Output is correct |
12 |
Correct |
55 ms |
9160 KB |
Output is correct |
13 |
Correct |
47 ms |
11100 KB |
Output is correct |
14 |
Correct |
74 ms |
13372 KB |
Output is correct |
15 |
Correct |
53 ms |
13368 KB |
Output is correct |
16 |
Correct |
36 ms |
13140 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
96 ms |
13140 KB |
Output is correct |
23 |
Correct |
84 ms |
12884 KB |
Output is correct |
24 |
Correct |
83 ms |
9556 KB |
Output is correct |
25 |
Correct |
89 ms |
13336 KB |
Output is correct |
26 |
Correct |
53 ms |
14228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
74 ms |
13136 KB |
Output is correct |
12 |
Correct |
55 ms |
9160 KB |
Output is correct |
13 |
Correct |
47 ms |
11100 KB |
Output is correct |
14 |
Correct |
74 ms |
13372 KB |
Output is correct |
15 |
Correct |
53 ms |
13368 KB |
Output is correct |
16 |
Correct |
36 ms |
13140 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
96 ms |
13140 KB |
Output is correct |
23 |
Correct |
84 ms |
12884 KB |
Output is correct |
24 |
Correct |
83 ms |
9556 KB |
Output is correct |
25 |
Correct |
89 ms |
13336 KB |
Output is correct |
26 |
Correct |
53 ms |
14228 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
132 ms |
14196 KB |
Output is correct |
35 |
Correct |
126 ms |
13604 KB |
Output is correct |
36 |
Correct |
126 ms |
14672 KB |
Output is correct |
37 |
Correct |
120 ms |
14892 KB |
Output is correct |
38 |
Correct |
59 ms |
14424 KB |
Output is correct |
39 |
Correct |
28 ms |
9044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
74 ms |
13136 KB |
Output is correct |
12 |
Correct |
55 ms |
9160 KB |
Output is correct |
13 |
Correct |
47 ms |
11100 KB |
Output is correct |
14 |
Correct |
74 ms |
13372 KB |
Output is correct |
15 |
Correct |
53 ms |
13368 KB |
Output is correct |
16 |
Correct |
36 ms |
13140 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
96 ms |
13140 KB |
Output is correct |
23 |
Correct |
84 ms |
12884 KB |
Output is correct |
24 |
Correct |
83 ms |
9556 KB |
Output is correct |
25 |
Correct |
89 ms |
13336 KB |
Output is correct |
26 |
Correct |
53 ms |
14228 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
132 ms |
14196 KB |
Output is correct |
35 |
Correct |
126 ms |
13604 KB |
Output is correct |
36 |
Correct |
126 ms |
14672 KB |
Output is correct |
37 |
Correct |
120 ms |
14892 KB |
Output is correct |
38 |
Correct |
59 ms |
14424 KB |
Output is correct |
39 |
Correct |
28 ms |
9044 KB |
Output is correct |
40 |
Correct |
4 ms |
860 KB |
Output is correct |
41 |
Correct |
5 ms |
860 KB |
Output is correct |
42 |
Correct |
3 ms |
860 KB |
Output is correct |
43 |
Correct |
3 ms |
980 KB |
Output is correct |
44 |
Correct |
194 ms |
15700 KB |
Output is correct |
45 |
Correct |
172 ms |
15700 KB |
Output is correct |
46 |
Correct |
200 ms |
15888 KB |
Output is correct |
47 |
Correct |
172 ms |
15900 KB |
Output is correct |
48 |
Correct |
71 ms |
15600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
1292 KB |
Output is correct |
27 |
Correct |
6 ms |
1116 KB |
Output is correct |
28 |
Correct |
5 ms |
1116 KB |
Output is correct |
29 |
Correct |
5 ms |
860 KB |
Output is correct |
30 |
Correct |
4 ms |
856 KB |
Output is correct |
31 |
Correct |
5 ms |
860 KB |
Output is correct |
32 |
Correct |
5 ms |
872 KB |
Output is correct |
33 |
Correct |
3 ms |
860 KB |
Output is correct |
34 |
Correct |
5 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
980 KB |
Output is correct |
38 |
Correct |
4 ms |
856 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
74 ms |
13136 KB |
Output is correct |
51 |
Correct |
55 ms |
9160 KB |
Output is correct |
52 |
Correct |
47 ms |
11100 KB |
Output is correct |
53 |
Correct |
74 ms |
13372 KB |
Output is correct |
54 |
Correct |
53 ms |
13368 KB |
Output is correct |
55 |
Correct |
36 ms |
13140 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
600 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
2 ms |
604 KB |
Output is correct |
61 |
Correct |
96 ms |
13140 KB |
Output is correct |
62 |
Correct |
84 ms |
12884 KB |
Output is correct |
63 |
Correct |
83 ms |
9556 KB |
Output is correct |
64 |
Correct |
89 ms |
13336 KB |
Output is correct |
65 |
Correct |
53 ms |
14228 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
452 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
460 KB |
Output is correct |
70 |
Correct |
4 ms |
860 KB |
Output is correct |
71 |
Correct |
2 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
132 ms |
14196 KB |
Output is correct |
74 |
Correct |
126 ms |
13604 KB |
Output is correct |
75 |
Correct |
126 ms |
14672 KB |
Output is correct |
76 |
Correct |
120 ms |
14892 KB |
Output is correct |
77 |
Correct |
59 ms |
14424 KB |
Output is correct |
78 |
Correct |
28 ms |
9044 KB |
Output is correct |
79 |
Correct |
4 ms |
860 KB |
Output is correct |
80 |
Correct |
5 ms |
860 KB |
Output is correct |
81 |
Correct |
3 ms |
860 KB |
Output is correct |
82 |
Correct |
3 ms |
980 KB |
Output is correct |
83 |
Correct |
194 ms |
15700 KB |
Output is correct |
84 |
Correct |
172 ms |
15700 KB |
Output is correct |
85 |
Correct |
200 ms |
15888 KB |
Output is correct |
86 |
Correct |
172 ms |
15900 KB |
Output is correct |
87 |
Correct |
71 ms |
15600 KB |
Output is correct |
88 |
Correct |
588 ms |
31500 KB |
Output is correct |
89 |
Correct |
402 ms |
24920 KB |
Output is correct |
90 |
Correct |
389 ms |
25936 KB |
Output is correct |
91 |
Correct |
356 ms |
23764 KB |
Output is correct |
92 |
Correct |
257 ms |
18260 KB |
Output is correct |
93 |
Correct |
374 ms |
24228 KB |
Output is correct |
94 |
Correct |
378 ms |
20936 KB |
Output is correct |
95 |
Correct |
97 ms |
20568 KB |
Output is correct |
96 |
Correct |
361 ms |
31384 KB |
Output is correct |
97 |
Correct |
52 ms |
17236 KB |
Output is correct |
98 |
Correct |
125 ms |
20560 KB |
Output is correct |
99 |
Correct |
151 ms |
20612 KB |
Output is correct |