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;
typedef long long ll;
#define rep(a,b) for (int a = 0; a < (b); ++a)
#define pb push_back
#define all(t) t.begin(), t.end()
struct Element
{
int val, idx;
bool operator < (const Element &element) const
{
return val < element.val;
}
};
const int MAXN = 1e5+4e5+50;
int n = 0, wyn = -1;
int A[MAXN];
int B[MAXN];
int C[MAXN];
bool czy_usunelismy[MAXN];
vector<Element> V1;
vector<Element> V2;
vector<Element> V3;
vector<int> spr;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i,n) cin >> A[i] >> B[i] >> C[i];
V1.assign(n,{}), V2.assign(n,{}), V3.assign(n,{});
rep(i,n) V1[i] = {A[i],i}, V2[i] = {B[i],i}, V3[i] = {C[i],i};
sort(all(V1)), sort(all(V2)), sort(all(V3));
while(V1.size() > 0 and V2.size() > 0 and V3.size() > 0)
{
spr = vector<int>();
spr.pb(V1.back().idx), spr.pb(V2.back().idx), spr.pb(V3.back().idx);
for (auto x : spr)
{
int cnt = 0;
if (V1.back().val == A[x]) ++cnt;
if (V2.back().val == B[x]) ++cnt;
if (V3.back().val == C[x]) ++cnt;
if (cnt > 1) czy_usunelismy[x] = true;
}
bool czy_OK = true;
if (czy_usunelismy[V1.back().idx] == true)
{
V1.pop_back(), czy_OK = false;
}
if (czy_usunelismy[V2.back().idx] == true)
{
V2.pop_back(), czy_OK = false;
}
if (czy_usunelismy[V3.back().idx] == true)
{
V3.pop_back(), czy_OK = false;
}
if (czy_OK)
{
wyn = V1.back().val + V2.back().val + V3.back().val;
break;
}
}
cout << wyn << '\n';
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... |