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;
#define ll long long
const ll inf = 1e18;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
array<ll, 3> a[n];
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
sort(a, a + n);
ll ans = -1;
int cur = 0;
for (int i = 0; i < n; i++) {
while (a[cur][0] < a[i][0]) cur++;
auto solve = [&] () {
array<ll, 2> mx1[2];
for (int j = 0; j < 2; j++) {
mx1[j] = {-inf, -inf};
}
for (int j = 0; j < cur; j++) {
array<ll, 2> val = {a[j][1], -a[j][2]};
if (val[0] == mx1[0][0]) {
mx1[0] = max(mx1[0], val);
} else {
if (val > mx1[1]) {
mx1[1] = val;
}
if (mx1[1] > mx1[0]) {
swap(mx1[0], mx1[1]);
}
}
}
mx1[0][1] *= -1, mx1[1][1] *= -1;
for (int k = 0; k < 2; k++) {
array<ll, 2> mx2 = {-inf, -inf};
for (int j = 0; j < cur; j++) {
if (a[j][1] < mx1[k][0]) {
mx2 = max(mx2, {a[j][2], -a[j][1]});
}
}
mx2[1] *= -1;
if (mx1[k][0] > a[i][1] && mx1[k][0] > mx2[1] &&
mx2[0] > a[i][2] && mx2[0] > mx1[k][1]) {
ans = max(ans, a[i][0] + mx1[k][0] + mx2[0]);
}
}
};
solve();
for (int j = 0; j < cur; j++) {
swap(a[j][1], a[j][2]);
}
swap(a[i][1], a[i][2]);
solve();
for (int j = 0; j < cur; j++) {
swap(a[j][1], a[j][2]);
}
swap(a[i][1], a[i][2]);
}
cout << ans << '\n';
return 0;
}
# | 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... |