This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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;
lft = ii{-1, -1}, rht = ii{-1, -1};
REP (i, 0, n) {
while (ptr < i && get<1>(xyz[ptr]) < get<1>(xyz[i])) {
auto [x, y, z] = xyz[ptr++];
if (lft.FI != -1) {
if (x > rht.FI && y < lft.SE) {
rht = ii{x, z};
} else if (y > lft.SE && x < rht.FI) {
lft = ii{x, z};
}
}
auto [it, yes] = st.insert(ii{x, z});
if (!yes) {
continue;
}
cerr << "+ " << x << ' ' << z << '\n';
if (next(it) != st.end() && next(it) -> SE >= z) {
it = st.erase(it);
cerr << "- " << x << ' ' << z << '\n';
assert(next(it) == st.end() || it -> FI != next(it) -> FI);
assert(it == st.begin() || it -> FI != prev(it) -> FI);
assert(next(it) == st.end() || it -> SE > next(it) -> SE);
assert(it == st.begin() || it -> SE < prev(it) -> SE);
continue;
}
while (it != st.begin() && prev(it) -> SE <= z) {
cerr << "- " << prev(it) -> FI << ' ' << prev(it) -> SE << '\n';
st.erase(prev(it));
}
assert(next(it) == st.end() || it -> FI != next(it) -> FI);
assert(it == st.begin() || it -> FI != prev(it) -> FI);
assert(next(it) == st.end() || it -> SE > next(it) -> SE);
assert(it == st.begin() || it -> SE < prev(it) -> SE);
if (SZ(st) >= 2) {
lft = *st.begin();
rht = *prev(st.end());
}
}
if (SZ(st) >= 2) {
int mx = prev(st.end()) -> FI, mz = st.begin() -> SE;
int my = -INF;
auto [cx, cy, cz] = xyz[i];
if (cx < mx && cz < mz) {
my = cy;
}
if (my != -INF) {
mxto(ans, mx + my + mz);
}
}
if (lft.FI != -1) {
int mx = rht.FI, mz = lft.SE;
int my = -INF;
auto [cx, cy, cz] = xyz[i];
if (cx < mx && cz < mz) {
my = cy;
}
if (my != -INF) {
mxto(ans, mx + my + mz);
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |