// Programmer: Shadow1
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using str = string; // yay python!
#define i64 int64_t
#define show(x) cerr << (#x) << " = " << (x) << '\n';
#define output_vector(v) for(auto &x : v){cout << x << ' ';}cout << '\n';
#define output_pairvector(v) for(auto &x : v){cout << x.first << " " << x.second << '\n';}
#define read_vector(v) for(auto &x : v){cin >> x;}
#define vt vector
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define fir first
#define sec second
#define sz(x) ll(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
//
//
const int INF = 1e15;
void solve() {
int n; cin >> n;
priority_queue<pii> a, b, c;
for(int i=0; i<n; ++i) {
int x, y, z;
cin >> x >> y >> z;
a.push({x, i});
b.push({y, i});
c.push({z, i});
}
vector<bool> done(n);
for(int i=0; i<n; ++i) {
while(!a.empty() && done[a.top().sec]) a.pop();
while(!b.empty() && done[b.top().sec]) b.pop();
while(!c.empty() && done[c.top().sec]) c.pop();
if(a.empty() || b.empty() || c.empty()) break;
if(a.top().sec != b.top().sec && a.top().sec != c.top().sec && b.top().sec != c.top().sec) {
cout << a.top().fir + b.top().fir + c.top().fir << '\n';
return;
} else {
if(a.top().sec == b.top().sec || a.top().sec == c.top().sec)
done[a.top().sec] = true;
if(b.top().sec == c.top().sec)
done[b.top().sec] = true;
}
}
cout << -1 << '\n';
}
// CHECK YOUR OVERFLOWS!!!!
signed main() {
// freopen("output.txt", "w", stdout);
// freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
// cin >> T;
for(int tc = 1; tc <= T; ++tc) {
// cout << "Case #" << tc << ": ";
solve();
}
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... |