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>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 3>> a(n);
set<pair<int, int>, greater<>> mx[3];
for (int i = 0; i < n; ++i) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
mx[0].emplace(a[i][0], i);
mx[1].emplace(a[i][1], i);
mx[2].emplace(a[i][2], i);
}
while (mx[0].size() > 2) {
int i = mx[0].begin()->second;
int j = mx[1].begin()->second;
int k = mx[2].begin()->second;
array<int, 3> b{a[i][0], a[j][1], a[k][2]};
bool yay = true;
for (int x : {i, j, k}) {
int cnt = 0;
for (int p = 0; p < 3; ++p) {
cnt += a[x][p] == b[p];
}
if (cnt >= 2) {
yay = false;
mx[0].erase({a[x][0], x});
mx[1].erase({a[x][1], x});
mx[2].erase({a[x][2], x});
break;
}
}
if (yay) {
cout << b[0] + b[1] + b[2] << '\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... |