#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=151515;
int n,x[N],y[N],z[N]; bool del[N];
priority_queue<ii> X,Y,Z;
void solve(){
cin>>n;
foru(i,1,n){
cin>>x[i]>>y[i]>>z[i];
X.push({x[i],i});
Y.push({y[i],i});
Z.push({z[i],i});
}
while(true){
if(X.empty() || Y.empty() || Z.empty()){
cout<<"-1\n";
return;
}
int i=X.top().se, j=Y.top().se, k=Z.top().se;
if(y[i]==y[j] || z[i]==z[k]) del[i]=true;
if(x[j]==x[i] || z[j]==z[k]) del[j]=true;
if(x[k]==x[i] || y[k]==y[j]) del[k]=true;
if(!del[i] && !del[j] && !del[k]){
cout<<x[i]+y[j]+z[k]<<'\n';
return;
}
while(!X.empty() && del[X.top().se]) X.pop();
while(!Y.empty() && del[Y.top().se]) Y.pop();
while(!Z.empty() && del[Z.top().se]) Z.pop();
}
}
int32_t main(){
#define task "test"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
foru(i,1,tc){
solve();
}
}
Compilation message (stderr)
team.cpp: In function 'int32_t main()':
team.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | 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... |