#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 (v[x[j][p[j]].s])
p[j]--;
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;
}
v[q] = 1;
}
cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |