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 int long long
#define pi pair <int, int>
#define ppi pair <pi, int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
int n, t, c, f, g, h;
vector <pi> x, y, z;
bool removed[150005];
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
/*int randnums[200005];
void gen(){
for(int i = 0; i < 200005; i++){
randnums[i] = rng() / 200005 + 1;
//cout << randnums[i] << '\n';
}
}*/
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
memset(removed, 0, sizeof(removed));
cin >> n;
for(int i = 1; i <= n; i++){
cin >> f >> g >> h;
x.pb({f, i}), y.pb({g, i}), z.pb({h, i});
}
sort(all(x)), sort(all(y)), sort(all(z));
while(1){
while(!x.empty() and removed[x.back().se]) x.pop_back();
while(!y.empty() and removed[y.back().se]) y.pop_back();
while(!z.empty() and removed[z.back().se]) z.pop_back();
if(x.empty() or y.empty() or z.empty()){
cout << -1;
break;
}
int i = -1, j = -1, k = -1;
if(!x.empty()){
i = x.back().se;
//cout << x.back().fi << ' ' << i << ' ';
}
if(!y.empty()){
j = y.back().se;
//cout << y.back().fi << ' ' << j << ' ';
}
if(!z.empty()){
k = z.back().se;
//cout << z.back().fi << ' ' << k << ' ';
}
//cout << '\n';
if(i == j and j == k and i != -1) x.pop_back(), y.pop_back(), z.pop_back(), removed[i] = 1;
else if(i == j and i != -1) x.pop_back(), y.pop_back(), removed[i] = 1;
else if(i == k and i != -1) x.pop_back(), z.pop_back(), removed[i] = 1;
else if(j == k and j != -1) y.pop_back(), z.pop_back(), removed[j] = 1;
else{
cout << x.back().fi + y.back().fi + z.back().fi;
break;
}
}
}
# | 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... |