#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define all(x) x.begin(), x.end()
#define sz(x) ((int) ((x).size()))
#define pb push_back
#define F first
#define S second
#define FIO ios_base::sync_with_stdio(false); cin.tie(0)
const int N = 2e5 + 10;
const int K = 30;
int n;
int x[N];
int y[N];
int z[N];
bool k[N];
bool us[N];
int main() {
FIO;
cin >> n;
multiset<pii> sx, sy, sz;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> z[i];
sx.insert({x[i], i});
sy.insert({y[i], i});
sz.insert({z[i], i});
}
while (sz(sx)) {
int mx = prev(sx.end())->F;
int my = prev(sy.end())->F;
int mz = prev(sz.end())->F;
map<int, int> cnt;
for (int i = 0; i < n; i++) {
if (x[i] == mx) cnt[i]++;
if (y[i] == my) cnt[i]++;
if (z[i] == mz) cnt[i]++;
}
bool c = 0;
for (int i = 0; i < n; i++) {
if (cnt[i] > 1 and !k[i]) {
sx.erase(sx.find({x[i], i}));
sy.erase(sy.find({y[i], i}));
sz.erase(sz.find({z[i], i}));
k[i] = 1;
c = 1;
}
}
if (c == 0) break;
}
int cnt = K;
while (sz(sx) and cnt) {
us[prev(sx.end())->S] = 1;
sx.erase(prev(sx.end()));
cnt--;
}
cnt = K;
while (sz(sy) and cnt) {
us[prev(sy.end())->S] = 1;
sy.erase(prev(sy.end()));
cnt--;
}
cnt = K;
while (sz(sz) and cnt) {
us[prev(sz.end())->S] = 1;
sz.erase(prev(sz.end()));
cnt--;
}
vector<int> inc;
for (int i = 0; i < n; i++) {
if (us[i]) inc.pb(i);
}
int ans = -1;
for (int i = 0; i < sz(inc); i++) {
for (int j = 0; j < sz(inc); j++) {
for (int l = 0; l < sz(inc); l++) {
int f = inc[i];
int s = inc[j];
int t = inc[l];
if (x[f] <= x[s] or x[f] <= x[t]) continue;
if (y[s] <= y[f] or y[s] <= y[t]) continue;
if (z[t] <= z[s] or z[t] <= z[f]) continue;
ans = max(ans, x[f] + y[s] + z[t]);
}
}
}
cout << ans << endl;
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... |