#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)
template <class T>
bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#ifndef DEBUG
#define cerr if(0) cerr
#endif
const int MAXN = 150005;
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
int n;
iii xyz[MAXN];
set<ii> st[2];
ii lft, rht;
int ans;
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n;
REP (i, 0, n) {
int x, y, z; cin >> x >> y >> z;
xyz[i] = {x, y, z};
}
sort(xyz, xyz + n, [&] (iii l, iii r) {
return get<1>(l) < get<1>(r);
});
ans = -1;
int ptr = 0;
int mx[2] = {-1, -1}, mz[2] = {-1, -1};
REP (i, 0, n) {
while (ptr < i && get<1>(xyz[ptr]) < get<1>(xyz[i])) {
auto [x, y, z] = xyz[ptr++];
cerr << x << ' ' << z << '\n';
{
cerr << ' ' << 0 << ' ' << mx[0] << ' ' << mz[0] << '\n';
auto [ptr, yes] = st[0].insert({x, z});
for (auto [a, b] : st[0]) {
cerr << " " << a << ' ' << b << '\n';
}
while (next(ptr) != st[0].end() && next(ptr) -> SE < z) {
bool bz = mz[0] <= z;
bool bx = mx[0] <= next(ptr) -> FI;
if (bx && bz) {
mz[0] = z;
mx[0] = next(ptr) -> FI;
}
st[0].erase(next(ptr));
}
if (ptr != st[0].begin() && prev(ptr) -> SE > z) {
bool bz = mz[0] <= prev(ptr) -> SE;
bool bx = mx[0] <= x;
cerr << " " << x << ' ' << (prev(ptr) -> SE) << '\n';
if (bx && bz) {
mz[0] = prev(ptr) -> SE;
mx[0] = x;
}
st[0].erase(ptr);
}
}
{
cerr << ' ' << 1 << ' ' << mx[1] << ' ' << mz[1] << '\n';
auto [ptr, yes] = st[1].insert({x, z});
while (ptr != st[1].begin() && prev(ptr) -> SE > z) {
bool bz = mz[1] <= prev(ptr) -> SE;
bool bx = mx[1] <= x;
if (bx && bz) {
mz[1] = prev(ptr) -> SE;
mx[1] = x;
}
st[1].erase(prev(ptr));
}
if (next(ptr) != st[1].end() && next(ptr) -> SE < z) {
bool bz = mz[1] <= z;
bool bx = mx[1] <= next(ptr) -> FI;
if (bx && bz) {
mz[1] = z;
mx[1] = next(ptr) -> FI;
}
st[1].erase(ptr);
}
}
}
REP (z, 0, 2) {
int my = -INF;
auto [cx, cy, cz] = xyz[i];
if (mx[z] == -1) continue;
if (cx < mx[z] && cz < mz[z]) {
my = cy;
}
if (my != -INF) {
mxto(ans, mx[z] + my + mz[z]);
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
40 ms |
2004 KB |
Output is correct |
12 |
Correct |
23 ms |
1492 KB |
Output is correct |
13 |
Correct |
26 ms |
1680 KB |
Output is correct |
14 |
Correct |
36 ms |
2000 KB |
Output is correct |
15 |
Correct |
26 ms |
2024 KB |
Output is correct |
16 |
Correct |
24 ms |
1964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
40 ms |
2004 KB |
Output is correct |
12 |
Correct |
23 ms |
1492 KB |
Output is correct |
13 |
Correct |
26 ms |
1680 KB |
Output is correct |
14 |
Correct |
36 ms |
2000 KB |
Output is correct |
15 |
Correct |
26 ms |
2024 KB |
Output is correct |
16 |
Correct |
24 ms |
1964 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
52 ms |
2016 KB |
Output is correct |
23 |
Correct |
45 ms |
2028 KB |
Output is correct |
24 |
Correct |
35 ms |
1584 KB |
Output is correct |
25 |
Correct |
46 ms |
2004 KB |
Output is correct |
26 |
Correct |
29 ms |
1988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
40 ms |
2004 KB |
Output is correct |
12 |
Correct |
23 ms |
1492 KB |
Output is correct |
13 |
Correct |
26 ms |
1680 KB |
Output is correct |
14 |
Correct |
36 ms |
2000 KB |
Output is correct |
15 |
Correct |
26 ms |
2024 KB |
Output is correct |
16 |
Correct |
24 ms |
1964 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
52 ms |
2016 KB |
Output is correct |
23 |
Correct |
45 ms |
2028 KB |
Output is correct |
24 |
Correct |
35 ms |
1584 KB |
Output is correct |
25 |
Correct |
46 ms |
2004 KB |
Output is correct |
26 |
Correct |
29 ms |
1988 KB |
Output is correct |
27 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
40 ms |
2004 KB |
Output is correct |
12 |
Correct |
23 ms |
1492 KB |
Output is correct |
13 |
Correct |
26 ms |
1680 KB |
Output is correct |
14 |
Correct |
36 ms |
2000 KB |
Output is correct |
15 |
Correct |
26 ms |
2024 KB |
Output is correct |
16 |
Correct |
24 ms |
1964 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
52 ms |
2016 KB |
Output is correct |
23 |
Correct |
45 ms |
2028 KB |
Output is correct |
24 |
Correct |
35 ms |
1584 KB |
Output is correct |
25 |
Correct |
46 ms |
2004 KB |
Output is correct |
26 |
Correct |
29 ms |
1988 KB |
Output is correct |
27 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |