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;
int main(){
int n;
cin>>n;
int a[n+1][3];
for (int i=1; i<=n; i++){
for (int j=0; j<3; j++) cin>>a[i][j];
}
priority_queue <pair <int,int> > pq[3];
for (int i=1; i<=n; i++){
for (int j=0; j<3; j++) pq[j].push(make_pair(a[i][j],i));
}
bool removed[n+1];
for (int i=1; i<=n; i++) removed[i]=0;
for (;;){
if (!pq[0].size()||!pq[1].size()||!pq[2].size()) break;
bool ok=1;
for (int j=0; j<3; j++){
if (removed[pq[j].top().second]){
pq[j].pop();
ok=0;
break;
}
for (int k=0; k<3; k++){
if (j==k) continue;
if (a[pq[j].top().second][k]==pq[k].top().first){
removed[pq[j].top().second]=1;
pq[j].pop();
ok=0;
break;
}
}
if (!ok) break;
}
if (ok){
cout<<pq[0].top().first+pq[1].top().first+pq[2].top().first<<'\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... |