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>
//#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
using namespace std;
#define int long long
#define ll long long
#define XX first
#define YY second
#define pb push_back
#define sz (x) int(x.size())
#define pf pop_front
#define pob pop_back
#define pff push_front
const int NMAX = 2e5 + 100;
set <pair <int, int>> xx, yy, zz;
int x[NMAX + 1], y[NMAX + 1], z[NMAX + 1];
signed main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, sum = -1;
    cin >> n;
    for (int i = 1; i <= n; ++ i){
        cin >> x[i] >> y[i] >> z[i];
        xx.insert ({x[i], i});
        yy.insert ({y[i], i});
        zz.insert ({z[i], i});
    }
    while (!xx.empty() && !yy.empty() && !zz.empty()){
        int x1 = xx.rbegin()->second;
        int y1 = yy.rbegin()->second;
        int z1 = zz.rbegin()->second;
        if (y[x1] >= y[y1] || z[x1] >= z[z1]){
            xx.erase({x[x1], x1});
            yy.erase({y[x1], x1});
            zz.erase({z[x1], x1});
            continue;
        }
        if (x[y1] >= x[x1] || z[y1] >= z[z1]){
            xx.erase({x[y1], y1});
            yy.erase({y[y1], y1});
            zz.erase({z[y1], y1});
            continue;
        }
        if (x[z1] >= x[x1] || y[z1] >= y[y1]){
            xx.erase({x[z1], z1});
            yy.erase({y[z1], z1});
            zz.erase({z[z1], z1});
            continue;
        }
        sum = x[x1] + y[y1] + z[z1];
        break;
    }
    cout << sum;
    return 0 ^ 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... |