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(0);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
set<pair<int, int>> xx, yy, zz;
int x[n], y[n], z[n];
for(int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> z[i];
xx.insert({x[i], i});
yy.insert({y[i], i});
zz.insert({z[i], i});
}
while(!xx.empty()) {
int pos = (--xx.end())->second;
if(y[pos] == (--yy.end())->first || z[pos] == (--zz.end())->first) {
xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
continue;
}
pos = (--yy.end())->second;
if(x[pos] == (--xx.end())->first || z[pos] == (--zz.end())->first) {
xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
continue;
}
pos = (--zz.end())->second;
if(x[pos] == (--xx.end())->first || y[pos] == (--yy.end())->first) {
xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
continue;
}
cout << (--xx.end())->first + (--yy.end())->first + (--zz.end())->first;
return 0;
}
cout << -1;
}
# | 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... |