#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define mp make_pair
#define pb push_back
#define INF (ll)2e18
#define MOD (ll)(1e9+7)
void solve(){
ll n; cin >> n;
map<ll, vector<pair<ll, ll>>> a;
for (ll i=0; i<n; i++){
ll x, y, z; cin >> x >> y >> z;
a[x].push_back({y, z});
}
set<pair<ll, ll>> yz, zy;
ll res=-1;
for (auto &[x, ar]:a){
if (yz.size()>=2){
for (auto [y, z]:ar){
pair<ll, ll> yzt = *yz.rbegin();
pair<ll, ll> zyt = *zy.rbegin();
pair<ll, ll> yzpt, zypt; yzpt=zypt={-1, -1};
auto iter1 = yz.upper_bound({yzt.ff-1, INF});
auto iter2 = zy.upper_bound({zyt.ff-1, INF});
if (iter1!=yz.begin()){
iter1--; yzpt = *iter1;
}
if (iter2!=zy.begin()){
iter2--; zypt = *iter2;
}
swap(zyt.ff, zyt.ss); swap(zypt.ff, zypt.ss);
vector<pair<ll, ll>> cur = {zyt, yzt, zypt, yzpt};
for (ll i=0; i<4; i++){
for (ll j=i+1; j<4; j++){
if (cur[i].ff!=-1 and cur[j].ff!=-1){
if (cur[i].ff>cur[j].ff and cur[i].ss<cur[j].ss and cur[i].ff>y and cur[j].ss>z){
res=max(res, cur[i].ff+cur[j].ss+x);
}else if (cur[i].ff<cur[j].ff and cur[i].ss>cur[j].ss and cur[i].ss>z and cur[j].ff>y){
res=max(res, x+cur[i].ss+cur[j].ff);
}
}
}
}
}
}
for (auto [y, z]:ar){
yz.insert({y, z});
zy.insert({z, y});
}
}
cout << res << ln;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifdef LOCAL
auto start = chrono::high_resolution_clock::now();
#endif
ll t=1;
// cin >> t;
for (ll c=1; c<=t; c++) solve();
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
}
# | 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... |