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;
int main() {
int n;
cin >> n;
set<vector<int>> x, y, z;
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
x.insert({a, b, c});
y.insert({b, c, a});
z.insert({c, a, b});
}
int ans = -1;
while (x.size()) {
vector<int> a = *x.rbegin(), b = *y.rbegin(), c = *z.rbegin();
if (a[1] >= b[0]) {
x.erase(a);
swap(a[0], a[1]);
swap(a[1], a[2]);
y.erase(a);
swap(a[0], a[1]);
swap(a[1], a[2]);
z.erase(a);
} else if (b[1] >= c[0]) {
y.erase(b);
swap(b[0], b[1]);
swap(b[1], b[2]);
z.erase(b);
swap(b[0], b[1]);
swap(b[1], b[2]);
x.erase(b);
} else if (c[1] >= a[0]) {
z.erase(c);
swap(c[0], c[1]);
swap(c[1], c[2]);
x.erase(c);
swap(c[0], c[1]);
swap(c[1], c[2]);
y.erase(c);
} else {
ans = a[0] + b[0] + c[0];
break;
}
}
cout << ans << "\n";
}
# | 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... |