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 endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=150007;
int x[N],y[N],z[N];
bool del[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
priority_queue<pair<int,int>>Qx,Qy,Qz;
for(int i=1;i<=n;i++)
{
cin>>x[i]>>y[i]>>z[i];
Qx.push({x[i],i});
Qy.push({y[i],i});
Qz.push({z[i],i});
}
while(true)
{
while(sz(Qx)>0&&del[Qx.top().nd]) Qx.pop();
while(sz(Qy)>0&&del[Qy.top().nd]) Qy.pop();
while(sz(Qz)>0&&del[Qz.top().nd]) Qz.pop();
if(sz(Qx)==0||sz(Qy)==0||sz(Qz)==0) break;
int i=Qx.top().nd;
// cout<<"i: "<<i<<endl;
if(y[i]==Qy.top().st||z[i]==Qz.top().st)
{
del[i]=1;
continue;
}
int j=Qy.top().nd;
// cout<<"j: "<<j<<endl;
if(x[j]==Qx.top().st||z[j]==Qz.top().st)
{
del[j]=1;
continue;
}
int k=Qz.top().nd;
// cout<<"k: "<<k<<endl;
if(x[k]==Qx.top().st||y[k]==Qy.top().st)
{
del[k]=1;
continue;
}
cout<<x[i]+y[j]+z[k];
return 0;
}
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... |