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;
const int MX = 5e5;
int n;
int x[MX], y[MX], z[MX];
int sx[MX], sy[MX], sz[MX];
int main() {
// input
cin >> n;
for (int i=0; i<n; i++)
cin >> x[i] >> y[i] >> z[i];
// sort by x, y and z
for (int i=0; i<n; i++)
sx[i] = sy[i] = sz[i] = i;
sort(sx,sx+n,[](int i, int j) {return x[i] > x[j];});
sort(sy,sy+n,[](int i, int j) {return y[i] > y[j];});
sort(sz,sz+n,[](int i, int j) {return z[i] > z[j];});
int a=0, b=0, c=0;
while (a != n && b != n && c != n) {
int cx = sx[a];
int cy = sy[b];
int cz = sz[c];
if (y[cx] >= y[cy] || z[cx] >= z[cz]) {
a++;
continue;
}
if (x[cy] >= x[cx] || z[cy] >= z[cz]) {
b++;
continue;
}
if (x[cz] >= x[cx] || y[cz] >= y[cy]) {
c++;
continue;
}
break;
}
if (a != n && b != n && c != n) {
cout << x[sx[a]] + y[sy[b]] + z[sz[c]] << endl;
} else {
cout << -1 << endl;
}
}
# | 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... |