#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
#define int long long
void solve() {
int N;
std::cin >> N;
std::vector<int> xx(N + 1), yy(N + 1), zz(N + 1);
for(int i = 1; i <= N; i++) {
std::cin >> xx[i] >> yy[i] >> zz[i];
}
int tr = 0;
std::vector<int> to_pr[10];
std::vector<int> w = {1, 2, 3};
do {
for(int i = 0; i < 3; i++) {
to_pr[tr].push_back(w[i]);
}
tr += 1;
} while(next_permutation(w.begin(), w.end()));
std::vector<int> x(N + 1), y(N + 1), z(N + 1);
int ans = - 1;
auto Do = [&] () {
for(int a = N; a >= 1; a--) {
for(int b = a - 1; b >= 1; b--) {
if(x[a] <= x[b] || y[b] <= y[a]) {
continue;
}
for(int c = 1; c < a; c++) {
if(x[c] < x[a] && y[c] < y[b] && z[c] > std::max(z[a], z[b])) {
ans = std::max(ans, x[a] + y[b] + z[c]);
}
}
}
}
};
for(int i = 0; i < 6; i++) {
if(to_pr[i][0] == 1) {
for(int i = 1; i <= N; i++) {
x[i] = xx[i];
}
}
if(to_pr[i][0] == 2) {
for(int i = 1; i <= N; i++) {
x[i] = yy[i];
}
}
if(to_pr[i][0] == 3) {
for(int i = 1; i <= N; i++) {
x[i] = zz[i];
}
}
if(to_pr[i][1] == 1) {
for(int i = 1; i <= N; i++) {
y[i] = xx[i];
}
}
if(to_pr[i][1] == 2) {
for(int i = 1; i <= N; i++) {
y[i] = yy[i];
}
}
if(to_pr[i][1] == 3) {
for(int i = 1; i <= N; i++) {
y[i] = zz[i];
}
}
if(to_pr[i][2] == 1) {
for(int i = 1; i <= N; i++) {
z[i] = xx[i];
}
}
if(to_pr[i][2] == 2) {
for(int i = 1; i <= N; i++) {
z[i] = yy[i];
}
}
if(to_pr[i][2] == 3) {
for(int i = 1; i <= N; i++) {
z[i] = zz[i];
}
}
for(int C = 0; C < 2; C++, reverse(x.begin() + 1, x.end()), reverse(y.begin() + 1, y.end()), reverse(z.begin() + 1, z.end())) {
Do();
}
}
std::cout << ans;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//std::cin >> t;
while (t--) {
solve();
}
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... |