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 <array>
#include <algorithm>
#define ll long long
using namespace std;
array <ll, 3> A[150000], B[150000], C[150000];
bool ok;
ll n;
int main() {
cin >> n;
for (int i=0; i<n; ++i) {
for (int j=0; j<3; ++j) {
cin >> A[i][j];
B[i][j] = C[i][j] = A[i][j];
}
}
sort(A, A+n, [](auto a, auto b) {
return a[0] > b[0];
});
sort(B, B+n, [](auto a, auto b) {
return a[1] > b[1];
});
sort(C, C+n, [](auto a, auto b) {
return a[2] > b[2];
});
int i = 0, j = 0, k = 0;
while (i < n && j < n && k < n) {
ok = 0;
while (j < n && A[i][0] <= B[j][0]) ++j, ok = 1;
while (k < n && A[i][0] <= C[k][0]) ++k, ok = 1;
if (j >= n || k >= n) break;
while (i < n && B[j][1] <= A[i][1]) ++i, ok = 1;
while (k < n && B[j][1] <= C[k][1]) ++k, ok = 1;
if (i >= n || k >= n) break;
while (i < n && C[k][2] <= A[i][2]) ++i, ok = 1;
while (j < n && C[k][2] <= B[j][2]) ++j, ok = 1;
if (i >= n || j >= n) break;
if (!ok) {
cout << A[i][0] + B[j][1] + C[k][2] << '\n';
return 0;
}
}
cout << "-1\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... |