#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int32_t main () {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> x(n + 1), y(n + 1), z(n + 1);
using pii = pair<int, int>;
priority_queue<pii> X, Y, Z;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> z[i];
X.emplace(x[i], i);
Y.emplace(y[i], i);
Z.emplace(z[i], i);
}
vector<bool> del(n + 1);
#define se second
while (1) {
if(X.empty() || Y.empty() || Z.empty()) {
return cout << -1, 0;
}
int i = X.top().se, j = Y.top().se, k = Z.top().se;
if(y[i] == y[j] || z[i] == z[k]) del[i] = 1;
if(x[j] == x[i] || z[j] == z[k]) del[j] = 1;
if(x[k] == x[i] || y[k] == y[j]) del[k] = 1;
if(!del[i] && !del[j] && !del[k]) {
return cout << x[i] + y[j] + z[k], 0;
}
while (!X.empty() && del[X.top().se]) X.pop();
while (!Y.empty() && del[Y.top().se]) Y.pop();
while (!Z.empty() && del[Z.top().se]) Z.pop();
}
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... |