This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> x(n + 1), y(n + 1), z(n + 1);
map<pii, vector<int>> mp1, mp2, mp3;
vector<bool> ban(n + 1);
int m = n;
for (int i = 1; i <= n; i++){
cin>>x[i]>>y[i]>>z[i];
mp1[{x[i], y[i]}].pb(i);
mp2[{x[i], z[i]}].pb(i);
mp3[{y[i], z[i]}].pb(i);
}
multiset<int> sx, sy, sz;
for (int i = 1; i <= n; i++){
sx.ins(x[i]);
sy.ins(y[i]);
sz.ins(z[i]);
}
auto erase = [&](int i){
ban[i] = 1; m--;
sx.erase(sx.find(x[i]));
sy.erase(sy.find(y[i]));
sz.erase(sz.find(z[i]));
};
while (m >= 3){
int f1 = *prev(sx.end()), f2 = *prev(sy.end()), f3 = *prev(sz.end());
bool ind = 1;
for (int j: mp1[{f1, f2}]){
if (ban[j]) continue;
ind = 0;
erase(j);
}
for (int j: mp2[{f1, f3}]){
if (ban[j]) continue;
ind = 0;
erase(j);
}
for (int j: mp3[{f2, f3}]){
if (ban[j]) continue;
ind = 0;
erase(j);
}
if (ind){
cout<<f1 + f2 + f3<<"\n";
return 0;
}
}
cout<<-1<<"\n";
}
# | 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... |