#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define sz(v) (int)v.size()
#define pb push_back
#define eb emplace_back
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
typedef long long ll;
using db = double;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<db>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
void setIO(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif
}
int main(){
setIO();
int N;
cin >> N;
vi X(N), Y(N), Z(N);
FOR(i, 0, N) cin >> X[i] >> Y[i] >> Z[i];
vi ix(N), iy(N), iz(N);
iota(all(ix), 0);
iota(all(iy), 0);
iota(all(iz), 0);
sort(all(ix), [&](int i, int j){ return X[i] > X[j]; });
sort(all(iy), [&](int i, int j){ return Y[i] > Y[j]; });
sort(all(iz), [&](int i, int j){ return Z[i] > Z[j]; });
int i = 0, j = 0, k = 0;
while(i < N && j < N && k < N){
int vx = X[ix[i]], vy = Y[iy[j]], vz = Z[iz[k]];
if(Y[ix[i]] >= Y[iy[j]] || Z[ix[i]] >= Z[iz[k]]){
++i;
continue;
}
if(X[iy[j]] >= X[ix[i]] || Z[iy[j]] >= Z[iz[k]]){
++j;
continue;
}
if(X[iz[k]] >= X[ix[i]] || Y[iz[k]] >= Y[iy[j]]){
++k;
continue;
}
cout << vx + vy + vz << '\n';
return 0;
}
cout << -1 << '\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... |