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 int long long
#define fi first
#define se second
#define pb push_back
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
static int n,i,state,x_id,y_id,z_id;
static pair<int,int> x[150005],y[150005],z[150005],x_max,y_max,z_max;
static tuple<int,int,int> t[150005];
bool elm[150005];
cin>>n;
for (i=1;i<n+1;i++)
{
cin>>x[i].fi>>y[i].fi>>z[i].fi;
x[i].se=y[i].se=z[i].se=i;
t[i]={x[i].fi,y[i].fi,z[i].fi};
elm[i]=false;
}
sort(x+1,x+n+1);
sort(y+1,y+n+1);
sort(z+1,z+n+1);
x_id=y_id=z_id=n;
x_max=x[n];
y_max=y[n];
z_max=z[n];
do
{
// cout<<x_max.fi<<y_max.fi<<z_max.fi<<"\n";
state=0;
if (elm[x_max.se]
or get<1>(t[x_max.se])>=get<1>(t[y_max.se])
or get<2>(t[x_max.se])>=get<2>(t[z_max.se])) state=1;
if (elm[y_max.se]
or get<0>(t[y_max.se])>=get<0>(t[x_max.se])
or get<2>(t[y_max.se])>=get<2>(t[z_max.se])) state=2;
if (elm[z_max.se]
or get<0>(t[z_max.se])>=get<0>(t[x_max.se])
or get<1>(t[z_max.se])>=get<1>(t[y_max.se])) state=3;
if (state==1)
{
if (x_id==1)
{
cout<<-1;return 0;
}
elm[x_max.se]=true;
x_id--;x_max=x[x_id];
}
if (state==2)
{
if (y_id==1)
{
cout<<-1;return 0;
}
elm[y_max.se]=true;
y_id--;y_max=y[y_id];
}
if (state==3)
{
if (z_id==1)
{
cout<<-1;return 0;
}
elm[z_max.se]=true;
z_id--;z_max=z[z_id];
}
}
while (state!=0);
if (state==-1) cout<<-1;
else cout<<x_max.fi + y_max.fi + z_max.fi;
}
# | 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... |