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];
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) {
while (j < n && A[i][0] <= B[j][0]) ++j;
while (k < n && A[i][0] <= C[k][0]) ++k;
if (j >= n || k >= n) break;
while (i < n && B[j][1] <= A[i][1]) ++i;
while (k < n && B[j][1] <= C[k][1]) ++k;
if (i >= n || k >= n) break;
while (i < n && C[k][2] <= A[i][2]) ++i;
while (j < n && C[k][2] <= B[j][2]) ++j;
if (i >= n || j >= n) break;
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... |