#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});
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;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
48 ms |
1980 KB |
Output is correct |
12 |
Correct |
27 ms |
1616 KB |
Output is correct |
13 |
Correct |
28 ms |
1692 KB |
Output is correct |
14 |
Correct |
39 ms |
2064 KB |
Output is correct |
15 |
Correct |
37 ms |
1960 KB |
Output is correct |
16 |
Correct |
27 ms |
2068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
48 ms |
1980 KB |
Output is correct |
12 |
Correct |
27 ms |
1616 KB |
Output is correct |
13 |
Correct |
28 ms |
1692 KB |
Output is correct |
14 |
Correct |
39 ms |
2064 KB |
Output is correct |
15 |
Correct |
37 ms |
1960 KB |
Output is correct |
16 |
Correct |
27 ms |
2068 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 |
58 ms |
2068 KB |
Output is correct |
23 |
Correct |
46 ms |
2008 KB |
Output is correct |
24 |
Correct |
36 ms |
1576 KB |
Output is correct |
25 |
Correct |
63 ms |
2064 KB |
Output is correct |
26 |
Correct |
28 ms |
1988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
48 ms |
1980 KB |
Output is correct |
12 |
Correct |
27 ms |
1616 KB |
Output is correct |
13 |
Correct |
28 ms |
1692 KB |
Output is correct |
14 |
Correct |
39 ms |
2064 KB |
Output is correct |
15 |
Correct |
37 ms |
1960 KB |
Output is correct |
16 |
Correct |
27 ms |
2068 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 |
58 ms |
2068 KB |
Output is correct |
23 |
Correct |
46 ms |
2008 KB |
Output is correct |
24 |
Correct |
36 ms |
1576 KB |
Output is correct |
25 |
Correct |
63 ms |
2064 KB |
Output is correct |
26 |
Correct |
28 ms |
1988 KB |
Output is correct |
27 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
48 ms |
1980 KB |
Output is correct |
12 |
Correct |
27 ms |
1616 KB |
Output is correct |
13 |
Correct |
28 ms |
1692 KB |
Output is correct |
14 |
Correct |
39 ms |
2064 KB |
Output is correct |
15 |
Correct |
37 ms |
1960 KB |
Output is correct |
16 |
Correct |
27 ms |
2068 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 |
58 ms |
2068 KB |
Output is correct |
23 |
Correct |
46 ms |
2008 KB |
Output is correct |
24 |
Correct |
36 ms |
1576 KB |
Output is correct |
25 |
Correct |
63 ms |
2064 KB |
Output is correct |
26 |
Correct |
28 ms |
1988 KB |
Output is correct |
27 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |