이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;
struct person {
    int x, y, z;
};
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    person v[n];
    vector<int> a, b, c;
    for (int i = 0; i < n; ++i) {
        cin >> v[i].x >> v[i].y >> v[i].z;
        a.push_back(i), b.push_back(i), c.push_back(i);
    }
    sort(all(a), [&](int &i, int &j) {
        return v[i].x < v[j].x;
    });
    sort(all(b), [&](int &i, int &j) {
        return v[i].y < v[j].y;
    });
    sort(all(c), [&](int &i, int &j) {
        return v[i].z < v[j].z;
    });
    while (!a.empty() && !b.empty() && !c.empty()) {
        if (v[a.back()].y >= v[b.back()].y || v[a.back()].z >= v[c.back()].z) {
            a.pop_back();
            continue;
        }
        if (v[b.back()].x >= v[a.back()].x || v[b.back()].z >= v[c.back()].z) {
            b.pop_back();
            continue;
        }
        if (v[c.back()].x >= v[a.back()].x || v[c.back()].y >= v[b.back()].y) {
            c.pop_back();
            continue;
        }
        if (a.back() == b.back()) {
            if (v[a.back()].x >= v[b.back()].y) {
                b.pop_back();
            } else {
                a.pop_back();
            }
        } else if (b.back() == c.back()) {
            if (v[b.back()].y >= v[c.back()].z) {
                c.pop_back();
            } else {
                b.pop_back();
            }
        } else if (a.back() == c.back()) {
            if (v[a.back()].x >= v[c.back()].z) {
                c.pop_back();
            } else {
                a.pop_back();
            }
        } else {
            cout << v[a.back()].x + v[b.back()].y + v[c.back()].z;
            return 0;
        }
    }
    cout << -1;
}
| # | 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... |