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;
struct zaw{
int x;
int y;
int z;
int i;
};
const int N = 15e4+3;
zaw arrX[N], arrY[N], arrZ[N];
int used[N];
bool compX(zaw fs, zaw sc){
return fs.x < sc.x;
}
bool compY(zaw fs, zaw sc){
return fs.y < sc.y;
}
bool compZ(zaw fs, zaw sc) {
return fs.z < sc.z;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x, y, z;
bool stp=false;
cin >> n;
for(int i=0; i<n; i++){
cin >> arrX[i].x >> arrX[i].y >> arrX[i].z;
arrX[i].i=i;
arrY[i]=arrX[i];
arrZ[i]=arrX[i];
}
sort(arrX, arrX+n, compX);
sort(arrY, arrY+n, compY);
sort(arrZ, arrZ+n, compZ);
x=y=z=n-1;
while(arrX[x].i==arrY[y].i || arrY[y].i==arrZ[z].i || arrZ[z].i==arrX[x].i){
if(used[arrX[x].i]!=0) x--;
if(used[arrY[y].i]!=0) y--;
if(used[arrZ[z].i]!=0) z--;
if(x<0 || y<0 || z<0){
stp=true;
break;
}
if(arrX[x].i==arrY[y].i){
used[arrX[x].i]++;
x--;
y--;
}
if(arrZ[z].i==arrY[y].i){
used[arrZ[z].i]++;
z--;
y--;
}
if(arrX[x].i==arrZ[z].i){
used[arrX[x].i]++;
x--;
z--;
}
if(x<0 || y<0 || z<0){
stp=true;
break;
}
}
if(stp) cout << "-1";
else cout << arrX[x].x+arrY[y].y+arrZ[z].z;
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... |