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;
#define fr(i) for(int i = 0; i < 3; i++)
#define pb push_back
#define all(a) a.begin(),a.end()
const int mxN = (int)1.5e5+10;
using ar = array<int,4>;
vector<ar> coder[3];
bool bad[mxN];
int n;
int32_t main() {
cin >> n; int i[] = {n-1,n-1,n-1};
for(int i = 0; i < n; i++){
int x,y,z; cin >>x>>y>>z;
fr(j) coder[j].pb({x,y,z,i});
}
fr(j) sort(all(coder[j]),[&](ar a, ar b){ return a[j] < b[j]; });
while(1){
fr(j){
while(i[j]>=0 and bad[coder[j][i[j]][3]]) i[j]--;
if(i[j]<0){cout<<-1;return 0;}
}
vector<int> val; val.clear();
fr(j) val.pb(coder[j][i[j]][j]);
fr(I) fr(j)
if(I!=j and coder[I][i[I]][j]==val[j])
bad[coder[I][i[I]][3]]=1;
bool ok = 1;
fr(j) ok&=!bad[coder[j][i[j]][3]];
if(ok){ cout << val[0]+val[1]+val[2]; 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... |