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>
#define all(v) v.begin(),v.end()
using namespace std;
int N;
int X[150001],Y[150001],Z[150001];
vector<pair<int,int>> VX,VY,VZ;
bool Used[150001];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N;
for (int i=1; i<=N; i++){
cin>>X[i]>>Y[i]>>Z[i];
VX.push_back({X[i],i});
VY.push_back({Y[i],i});
VZ.push_back({Z[i],i});
}
sort(all(VX));
sort(all(VY));
sort(all(VZ));
for (int x=N-1,y=N-1,z=N-1; x>=0&&y>=0&&z>=0;){
if (Y[VX[x].second]==VY[y].first||Z[VX[x].second]==VZ[z].first)
Used[VX[x].second]=true;
else if (X[VY[y].second]==VX[x].first||Z[VY[y].second]==VZ[z].first)
Used[VY[y].second]=true;
else if (X[VZ[z].second]==VX[x].first||Y[VZ[z].second]==VY[y].first)
Used[VZ[z].second]=true;
else{
cout<<VX[x].first+VY[y].first+VZ[z].first;
return 0;
}
while (x>=0&&Used[VX[x].second])
x--;
while (y>=0&&Used[VY[y].second])
y--;
while (z>=0&&Used[VZ[z].second])
z--;
}
cout<<"-1";
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... |