// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 15e4 + 7;
int n;
int mxy[4005][4005], mxz[4005][4005];
bool mark[N];
struct beaver {
int x, y, z, id;
} a[N], b[N], c[N];
bool cmpx(beaver A, beaver B) {
return A.x < B.x;
}
bool cmpy(beaver A, beaver B) {
return A.y < B.y;
}
bool cmpz(beaver A, beaver B) {
return A.z < B.z;
}
bool valid(beaver X, beaver Y, beaver Z) {
if(X.x <= max(Y.x, Z.x)) return 0;
if(Y.y <= max(X.y, Z.y)) return 0;
if(Z.z <= max(Y.z, X.z)) return 0;
return 1;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; i++) {
int x, y, z; cin >> x >> y >> z;
a[i] = b[i] = c[i] = {x, y, z, i};
}
sort(a + 1, a + n + 1, cmpx);
sort(b + 1, b + n + 1, cmpy);
sort(c + 1, c + n + 1, cmpz);
int cx = n, cy = n, cz = n;
while(cx and cy and cz) {
// cerr << a[cx].id << ' ' << b[cy].id << ' ' << c[cz].id << ln;
if(valid(a[cx], b[cy], c[cz])) {
cout << a[cx].x + b[cy].y + c[cz].z;
return 0;
}
if(a[cx].x <= max(b[cy].x, c[cz].x)) {
mark[a[cx].id] = 1;
}
if(b[cy].y <= max(a[cx].y, c[cz].y)) {
mark[b[cy].id] = 1;
}
if(c[cz].z <= max(b[cy].z, a[cx].z)) {
mark[c[cz].id] = 1;
}
while(cx and mark[a[cx].id]) cx--;
while(cy and mark[b[cy].id]) cy--;
while(cz and mark[c[cz].id]) cz--;
}
cout << -1 << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
team.cpp: In function 'int main()':
team.cpp:45:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(task ".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:46:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(task ".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |