#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct beaver {
int a,b,c;
};
bool comp1(beaver x, beaver y) {
return x.a < y.a;
}
bool comp2(beaver x, beaver y) {
return x.b < y.b;
}
bool comp3(beaver x, beaver y) {
return x.c < y.c;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<beaver> Bs(n);
for(int i=0; i<n; ++i) {
int a, b, c;
cin >> a >> b >> c;
Bs[i] = {a,b,c};
}
vector<beaver> A = Bs;
vector<beaver> B = Bs;
vector<beaver> C = Bs;
sort(A.begin(), A.end(), comp1);
sort(B.begin(), B.end(), comp2);
sort(C.begin(), C.end(), comp3);
while(A.size() && B.size() && C.size()) {
beaver a = A.back();
beaver b = B.back();
beaver c = C.back();
int max1 = max(max(a.a, b.a), c.a);
int max2 = max(max(a.b, b.b), c.b);
int max3 = max(max(a.c, b.c), c.c);
int w1=0, w2=0, w3=0;
if(a.a==max1) w1++;
if(a.b==max2) w1++;
if(a.c==max3) w1++;
if(b.a==max1) w2++;
if(b.b==max2) w2++;
if(b.c==max3) w2++;
if(c.a==max1) w3++;
if(c.b==max2) w3++;
if(c.c==max3) w3++;
if(w1==1 && w2==1 && w3==1) {
cout << max1 + max2 + max3 << "\n";
return 0;
} else if(w1 > 1) A.pop_back();
else if(w2 > 1) B.pop_back();
else if(w3 > 1) C.pop_back();
}
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... |