/**
* author: tourist
* created: 21.04.2025 16:49:29
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> x(n), y(n), z(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> z[i];
}
vector<pair<int, int>> sx, sy, sz;
for (int i = 0; i < n; i++) {
sx.emplace_back(x[i], i);
sy.emplace_back(y[i], i);
sz.emplace_back(z[i], i);
}
sort(sx.begin(), sx.end());
sort(sy.begin(), sy.end());
sort(sz.begin(), sz.end());
int ptr_x = n - 1, ptr_y = n - 1, ptr_z = n - 1;
vector<bool> vis(n);
while (ptr_x >= 0 && ptr_y >= 0 && ptr_z >= 0) {
while (ptr_x >= 0 && vis[sx[ptr_x].second]) {
ptr_x -= 1;
}
while (ptr_y >= 0 && vis[sy[ptr_y].second]) {
ptr_y -= 1;
}
if (ptr_z >= 0 && vis[sz[ptr_z].second]) {
ptr_z -= 1;
}
if (ptr_x < 0 || ptr_y < 0 || ptr_z < 0) {
break;
}
if (sx[ptr_x].second == sy[ptr_y].second) {
vis[sx[ptr_x].second] = true;
continue;
}
if (sy[ptr_y].second == sz[ptr_z].second) {
vis[sy[ptr_y].second] = true;
continue;
}
if (sx[ptr_x].second == sz[ptr_z].second) {
vis[sz[ptr_z].second] = true;
continue;
}
cout << sx[ptr_x].first + sy[ptr_y].first + sz[ptr_z].first << '\n';
return 0;
}
cout << -1 << '\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... |