#include <bits/stdc++.h>
using namespace std;
const int MAXN = 15e4+5;
const int inf = 2e9;
typedef long long ll;
typedef array<int, 2> arr2;
typedef array<int, 3> arr3;
arr3 points[MAXN];
int n;
const arr2 def({-1, -1});
arr2 get_prev(set<arr2> &vals, arr2 cur) {
auto v = vals.upper_bound(cur);
if (v == vals.begin()) return def;
return *(--v);
}
bool dom(arr2 a, arr2 b) {
return a[0] >= b[0] && a[1] >= b[1];
}
arr2 rev(arr2 a) {
return arr2({a[1], a[0]});
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) cin >> points[i][j];
}
sort(points, points+n);
set<arr2> tail({{inf, inf}});
set<arr2> tail_rev({{inf, inf}});
arr2 bst[2] = {def, def};
ll best = -1;
for (int j = 0; j < n;) {
int p = j;
int x = points[j][0];
while (points[j][0] == x) {
if (points[j][1] < bst[0][0] && points[j][2] < bst[1][1])
best = max(best, (ll)points[j][0]+bst[0][0]+bst[1][1]);
j++;
}
for (int i = p; i < j; i++) {
arr2 cur({points[i][1], points[i][2]});
if (tail.find(cur) != tail.end()) continue;
// case 1: add to tail
arr2 prv = get_prev(tail, cur);
arr2 nxt = *(tail.upper_bound(cur));
if (((prv != def && dom(cur, prv)) ||
(prv == def && dom(cur, bst[0]) && dom(cur, bst[1])))
&& dom(nxt, cur)) { // added to tail
tail.insert(cur);
tail_rev.insert(rev(cur));
continue;
}
// case 2: ignorable
if (cur[0] <= bst[0][0] && cur[1] <= bst[0][1]) {
continue;
}
// case 3: special insert
arr2 s = *tail.begin();
if (dom(s, cur)) {
if (cur[0] > bst[0][0]) {
bst[0] = cur;
}
else if (cur[1] > bst[1][1]) {
bst[1] = cur;
}
continue;
}
// case 4: lower insert
if (cur[1] < prv[1]) {
arr2 popped;
do {
popped = *tail.begin();
tail.erase(popped);
tail_rev.erase(rev(popped));
} while (popped != prv);
bst[0] = cur;
bst[1] = prv;
continue;
}
prv = rev(get_prev(tail_rev, rev(cur)));
nxt = rev(*tail_rev.upper_bound(rev(cur)));
assert(cur[0] < prv[0]);
arr2 popped;
do {
popped = *tail.begin();
tail.erase(popped);
tail_rev.erase(rev(popped));
} while (popped != prv);
bst[0] = prv;
bst[1] = cur;
}
}
cout << best << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
484 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
3 ms |
656 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
4 ms |
860 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
34 ms |
2140 KB |
Output is correct |
12 |
Correct |
21 ms |
1628 KB |
Output is correct |
13 |
Correct |
24 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2968 KB |
Output is correct |
15 |
Correct |
30 ms |
2904 KB |
Output is correct |
16 |
Correct |
27 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
34 ms |
2140 KB |
Output is correct |
12 |
Correct |
21 ms |
1628 KB |
Output is correct |
13 |
Correct |
24 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2968 KB |
Output is correct |
15 |
Correct |
30 ms |
2904 KB |
Output is correct |
16 |
Correct |
27 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
42 ms |
3320 KB |
Output is correct |
23 |
Correct |
38 ms |
2908 KB |
Output is correct |
24 |
Correct |
38 ms |
2396 KB |
Output is correct |
25 |
Correct |
39 ms |
3160 KB |
Output is correct |
26 |
Correct |
30 ms |
3152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
34 ms |
2140 KB |
Output is correct |
12 |
Correct |
21 ms |
1628 KB |
Output is correct |
13 |
Correct |
24 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2968 KB |
Output is correct |
15 |
Correct |
30 ms |
2904 KB |
Output is correct |
16 |
Correct |
27 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
42 ms |
3320 KB |
Output is correct |
23 |
Correct |
38 ms |
2908 KB |
Output is correct |
24 |
Correct |
38 ms |
2396 KB |
Output is correct |
25 |
Correct |
39 ms |
3160 KB |
Output is correct |
26 |
Correct |
30 ms |
3152 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
476 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
42 ms |
3408 KB |
Output is correct |
35 |
Correct |
44 ms |
3412 KB |
Output is correct |
36 |
Correct |
48 ms |
3664 KB |
Output is correct |
37 |
Correct |
47 ms |
4100 KB |
Output is correct |
38 |
Correct |
36 ms |
3672 KB |
Output is correct |
39 |
Correct |
19 ms |
2504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
34 ms |
2140 KB |
Output is correct |
12 |
Correct |
21 ms |
1628 KB |
Output is correct |
13 |
Correct |
24 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2968 KB |
Output is correct |
15 |
Correct |
30 ms |
2904 KB |
Output is correct |
16 |
Correct |
27 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
42 ms |
3320 KB |
Output is correct |
23 |
Correct |
38 ms |
2908 KB |
Output is correct |
24 |
Correct |
38 ms |
2396 KB |
Output is correct |
25 |
Correct |
39 ms |
3160 KB |
Output is correct |
26 |
Correct |
30 ms |
3152 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
476 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
42 ms |
3408 KB |
Output is correct |
35 |
Correct |
44 ms |
3412 KB |
Output is correct |
36 |
Correct |
48 ms |
3664 KB |
Output is correct |
37 |
Correct |
47 ms |
4100 KB |
Output is correct |
38 |
Correct |
36 ms |
3672 KB |
Output is correct |
39 |
Correct |
19 ms |
2504 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
42 ms |
4388 KB |
Output is correct |
45 |
Correct |
53 ms |
4592 KB |
Output is correct |
46 |
Correct |
54 ms |
4432 KB |
Output is correct |
47 |
Correct |
62 ms |
4596 KB |
Output is correct |
48 |
Correct |
43 ms |
4376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
484 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
3 ms |
656 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
4 ms |
860 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
34 ms |
2140 KB |
Output is correct |
51 |
Correct |
21 ms |
1628 KB |
Output is correct |
52 |
Correct |
24 ms |
2384 KB |
Output is correct |
53 |
Correct |
36 ms |
2968 KB |
Output is correct |
54 |
Correct |
30 ms |
2904 KB |
Output is correct |
55 |
Correct |
27 ms |
2908 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
42 ms |
3320 KB |
Output is correct |
62 |
Correct |
38 ms |
2908 KB |
Output is correct |
63 |
Correct |
38 ms |
2396 KB |
Output is correct |
64 |
Correct |
39 ms |
3160 KB |
Output is correct |
65 |
Correct |
30 ms |
3152 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
2 ms |
476 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
42 ms |
3408 KB |
Output is correct |
74 |
Correct |
44 ms |
3412 KB |
Output is correct |
75 |
Correct |
48 ms |
3664 KB |
Output is correct |
76 |
Correct |
47 ms |
4100 KB |
Output is correct |
77 |
Correct |
36 ms |
3672 KB |
Output is correct |
78 |
Correct |
19 ms |
2504 KB |
Output is correct |
79 |
Correct |
2 ms |
348 KB |
Output is correct |
80 |
Correct |
2 ms |
348 KB |
Output is correct |
81 |
Correct |
3 ms |
604 KB |
Output is correct |
82 |
Correct |
3 ms |
604 KB |
Output is correct |
83 |
Correct |
42 ms |
4388 KB |
Output is correct |
84 |
Correct |
53 ms |
4592 KB |
Output is correct |
85 |
Correct |
54 ms |
4432 KB |
Output is correct |
86 |
Correct |
62 ms |
4596 KB |
Output is correct |
87 |
Correct |
43 ms |
4376 KB |
Output is correct |
88 |
Correct |
48 ms |
6112 KB |
Output is correct |
89 |
Correct |
83 ms |
7596 KB |
Output is correct |
90 |
Correct |
59 ms |
6360 KB |
Output is correct |
91 |
Correct |
95 ms |
7100 KB |
Output is correct |
92 |
Correct |
60 ms |
5200 KB |
Output is correct |
93 |
Correct |
82 ms |
6996 KB |
Output is correct |
94 |
Correct |
83 ms |
7008 KB |
Output is correct |
95 |
Correct |
77 ms |
9296 KB |
Output is correct |
96 |
Correct |
148 ms |
19960 KB |
Output is correct |
97 |
Correct |
46 ms |
5968 KB |
Output is correct |
98 |
Correct |
119 ms |
13908 KB |
Output is correct |
99 |
Correct |
123 ms |
14324 KB |
Output is correct |