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 f first
#define s second
const int N = 150005;
pair<int, int> x[3][N];
int p[3], v[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++) {
cin >> x[j][i].f;
x[j][i].s = i;
}
for (int j = 0; j < 3; j++)
sort(x[j], x[j] + n);
p[0] = p[1] = p[2] = n - 1;
while (true) {
for (int j = 0; j < 3; j++)
while (p[j] >= 0 && v[x[j][p[j]].s])
p[j]--;
if (p[0] < 0) break;
int q = -1;
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
if (j != k && x[k][p[k]].f
== x[k][x[j][p[j]].s].f)
q = x[j][p[j]].s;
if (q < 0) {
cout << x[0][p[0]].f +
x[1][p[1]].f + x[2][p[2]].f;
return 0;
}
cerr << p[0] << '\n';
v[q] = 1;
}
cout << -1;
}
# | 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... |