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() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 3>> x(n);
for (auto &[a, b, c] : x) {
cin >> a >> b >> c;
}
auto y = x;
auto z = x;
sort(begin(x), end(x), [&](auto a, auto b) {
return a[0] < b[0];
});
sort(begin(y), end(y), [&](auto a, auto b) {
return a[1] < b[1];
});
sort(begin(z), end(z), [&](auto a, auto b) {
return a[2] < b[2];
});
while (!x.empty() && !y.empty() && !z.empty()) {
if (x.back()[1] >= y.back()[1] || x.back()[2] >= z.back()[2]) {
x.pop_back();
continue;
}
if (y.back()[0] >= x.back()[0] || y.back()[2] >= z.back()[2]) {
y.pop_back();
continue;
}
if (z.back()[0] >= x.back()[0] || z.back()[1] >= y.back()[1]) {
z.pop_back();
continue;
}
break;
}
if (x.empty() || y.empty() || z.empty()) {
cout << "-1\n";
} else {
cout << x.back()[0] + y.back()[1] + z.back()[2] << '\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... |