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<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 123;
using pii = pair<int,int>;
pii x[N], y[N], z[N];
int ix[N], iy[N], iz[N];
int used[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0 ; i < n ; ++ i) {
cin >> ix[i] >> iy[i] >> iz[i];
x[i] = {ix[i], i};
y[i] = {iy[i], i};
z[i] = {iz[i], i};
}
sort(x, x + n);
sort(y, y + n);
sort(z, z + n);
int a = n - 1, b = n - 1, c = n - 1;
while (a >= 0 && b >= 0 && c >= 0) {
int i = x[a].second, j = y[b].second, k = z[c].second;
if (iy[i] == iy[j] || iz[i] == iz[k] || used[i]) { used[i] = 1, --a; continue; }
if (ix[i] == ix[j] || iz[j] == iz[k] || used[j]) { used[j] = 1, --b; continue; }
if (iy[j] == iy[k] || ix[i] == ix[k] || used[k]) { used[k] = 1, --c; continue; }
if (ix[i] > ix[j] && ix[i] > ix[k] && iy[j] > iy[i] && iy[j] > iy[k] &&
iz[k] > iz[i] && iz[k] > iz[j]) {
cout << ix[i] + iy[j] + iz[k];
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... |