#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
int typ = 0;
struct player
{
int a,b,c, ind;
bool operator<(const player& other)
{
switch(typ)
{
case 1:
{
return a < other.a;
}
case 2:
{
return b < other.b;
}
case 3:
{
return c < other.c;
}
}
}
};
void solve()
{
int n;
cin >> n;
vector<player> players;
rep(i,n)
{
int a,b,c;
cin >> a >> b >> c;
players.pb({a,b,c,i});
}
vector<player> stack1 = players;
vector<player> stack2 = players;
vector<player> stack3 = players;
typ = 1;
sort(all(stack1));
typ = 2;
sort(all(stack2));
typ = 3;
sort(all(stack3));
while(!stack1.empty() && !stack2.empty() && !stack3.empty())
{
// cout << stack1.back().ind << " " << stack2.back().ind << " " << stack3.back().ind << " ind\n";
player g1 = stack1.back();
player g2 = stack2.back();
player g3 = stack3.back();
int maxa = max(max(g1.a,g2.a),g3.a);
int maxb = max(max(g1.b,g2.b),g3.b);
int maxc = max(max(g1.c,g2.c),g3.c);
int w1 = 0;
int w2 = 0;
int w3 = 0;
if(g1.a == maxa) w1++;
if(g1.b == maxb) w1++;
if(g1.c == maxc) w1++;
if(g2.a == maxa) w2++;
if(g2.b == maxb) w2++;
if(g2.c == maxc) w2++;
if(g3.a == maxa) w3++;
if(g3.b == maxb) w3++;
if(g3.c == maxc) w3++;
if(w1 > 1)
{
stack1.pop_back();
}
if(w2 > 1)
{
stack2.pop_back();
}
if(w3 > 1)
{
stack3.pop_back();
}
if(w1 == 1 && w2 == 1 && w3 == 1)
{
cout << maxa + maxb + maxc << "\n"; return;
}
}
cout << "-1\n";
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random();
int t = 1;
//cin >> t;
while(t--) solve();
}
Compilation message (stderr)
team.cpp: In member function 'bool player::operator<(const player&)':
team.cpp:45:5: warning: control reaches end of non-void function [-Wreturn-type]
45 | }
| ^| # | 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... |