#include <bits/stdc++.h>
#define fi first
#define se second
const int N = 200200;
const int mod = 1e9 + 7;
using namespace std;
int n;
bool used[N];
int x[N], y[N], z[N];
int main() {
#ifdef zxc
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin >> n;
vector<int> a(n), b(n), c(n);
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> z[i];
a[i - 1] = i;
b[i - 1] = i;
c[i - 1] = i;
}
sort(a.begin(), a.end(), [&](int i, int j){return x[i] > x[j]; });
sort(b.begin(), b.end(), [&](int i, int j){return y[i] > y[j]; });
sort(c.begin(), c.end(), [&](int i, int j){return z[i] > z[j]; });
int i = 0, j = 0, h = 0;
while (i < n && j < n && h < n) {
if (used[a[i]]) {
i++;
} else if (used[b[j]]) {
j++;
} else if (used[c[h]]) {
h++;
} else if (y[a[i]] == y[b[j]] || z[a[i]] == z[c[h]]) {
used[a[i++]] = true;
} else if (x[b[j]] == x[a[i]] || z[b[j]] == z[c[h]]) {
used[b[j++]] = true;
} else if (x[c[h]] == x[a[i]] || y[c[h]] == y[b[j]]) {
used[c[h++]] = true;
} else {
cout << x[a[i]] + y[b[j]] + z[c[h]] << "\n";
return 0;
}
}
cout << -1 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
640 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
452 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
452 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
29 ms |
4772 KB |
Output is correct |
12 |
Correct |
21 ms |
3292 KB |
Output is correct |
13 |
Correct |
22 ms |
4036 KB |
Output is correct |
14 |
Correct |
33 ms |
4872 KB |
Output is correct |
15 |
Correct |
28 ms |
4820 KB |
Output is correct |
16 |
Correct |
31 ms |
4888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
29 ms |
4772 KB |
Output is correct |
12 |
Correct |
21 ms |
3292 KB |
Output is correct |
13 |
Correct |
22 ms |
4036 KB |
Output is correct |
14 |
Correct |
33 ms |
4872 KB |
Output is correct |
15 |
Correct |
28 ms |
4820 KB |
Output is correct |
16 |
Correct |
31 ms |
4888 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
38 ms |
4988 KB |
Output is correct |
23 |
Correct |
33 ms |
4816 KB |
Output is correct |
24 |
Correct |
28 ms |
3788 KB |
Output is correct |
25 |
Correct |
40 ms |
5028 KB |
Output is correct |
26 |
Correct |
29 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
29 ms |
4772 KB |
Output is correct |
12 |
Correct |
21 ms |
3292 KB |
Output is correct |
13 |
Correct |
22 ms |
4036 KB |
Output is correct |
14 |
Correct |
33 ms |
4872 KB |
Output is correct |
15 |
Correct |
28 ms |
4820 KB |
Output is correct |
16 |
Correct |
31 ms |
4888 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
38 ms |
4988 KB |
Output is correct |
23 |
Correct |
33 ms |
4816 KB |
Output is correct |
24 |
Correct |
28 ms |
3788 KB |
Output is correct |
25 |
Correct |
40 ms |
5028 KB |
Output is correct |
26 |
Correct |
29 ms |
4952 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
44 ms |
5200 KB |
Output is correct |
35 |
Correct |
44 ms |
5040 KB |
Output is correct |
36 |
Correct |
55 ms |
5696 KB |
Output is correct |
37 |
Correct |
49 ms |
5580 KB |
Output is correct |
38 |
Correct |
35 ms |
5464 KB |
Output is correct |
39 |
Correct |
20 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
29 ms |
4772 KB |
Output is correct |
12 |
Correct |
21 ms |
3292 KB |
Output is correct |
13 |
Correct |
22 ms |
4036 KB |
Output is correct |
14 |
Correct |
33 ms |
4872 KB |
Output is correct |
15 |
Correct |
28 ms |
4820 KB |
Output is correct |
16 |
Correct |
31 ms |
4888 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
38 ms |
4988 KB |
Output is correct |
23 |
Correct |
33 ms |
4816 KB |
Output is correct |
24 |
Correct |
28 ms |
3788 KB |
Output is correct |
25 |
Correct |
40 ms |
5028 KB |
Output is correct |
26 |
Correct |
29 ms |
4952 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
44 ms |
5200 KB |
Output is correct |
35 |
Correct |
44 ms |
5040 KB |
Output is correct |
36 |
Correct |
55 ms |
5696 KB |
Output is correct |
37 |
Correct |
49 ms |
5580 KB |
Output is correct |
38 |
Correct |
35 ms |
5464 KB |
Output is correct |
39 |
Correct |
20 ms |
3532 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
57 ms |
5924 KB |
Output is correct |
45 |
Correct |
62 ms |
6116 KB |
Output is correct |
46 |
Correct |
59 ms |
6052 KB |
Output is correct |
47 |
Correct |
62 ms |
6140 KB |
Output is correct |
48 |
Correct |
39 ms |
5964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
640 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
452 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
452 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
29 ms |
4772 KB |
Output is correct |
51 |
Correct |
21 ms |
3292 KB |
Output is correct |
52 |
Correct |
22 ms |
4036 KB |
Output is correct |
53 |
Correct |
33 ms |
4872 KB |
Output is correct |
54 |
Correct |
28 ms |
4820 KB |
Output is correct |
55 |
Correct |
31 ms |
4888 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
344 KB |
Output is correct |
61 |
Correct |
38 ms |
4988 KB |
Output is correct |
62 |
Correct |
33 ms |
4816 KB |
Output is correct |
63 |
Correct |
28 ms |
3788 KB |
Output is correct |
64 |
Correct |
40 ms |
5028 KB |
Output is correct |
65 |
Correct |
29 ms |
4952 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
332 KB |
Output is correct |
70 |
Correct |
2 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
44 ms |
5200 KB |
Output is correct |
74 |
Correct |
44 ms |
5040 KB |
Output is correct |
75 |
Correct |
55 ms |
5696 KB |
Output is correct |
76 |
Correct |
49 ms |
5580 KB |
Output is correct |
77 |
Correct |
35 ms |
5464 KB |
Output is correct |
78 |
Correct |
20 ms |
3532 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
468 KB |
Output is correct |
81 |
Correct |
1 ms |
468 KB |
Output is correct |
82 |
Correct |
2 ms |
468 KB |
Output is correct |
83 |
Correct |
57 ms |
5924 KB |
Output is correct |
84 |
Correct |
62 ms |
6116 KB |
Output is correct |
85 |
Correct |
59 ms |
6052 KB |
Output is correct |
86 |
Correct |
62 ms |
6140 KB |
Output is correct |
87 |
Correct |
39 ms |
5964 KB |
Output is correct |
88 |
Correct |
73 ms |
7768 KB |
Output is correct |
89 |
Correct |
74 ms |
7840 KB |
Output is correct |
90 |
Correct |
72 ms |
7916 KB |
Output is correct |
91 |
Correct |
77 ms |
7872 KB |
Output is correct |
92 |
Correct |
68 ms |
6424 KB |
Output is correct |
93 |
Correct |
70 ms |
6672 KB |
Output is correct |
94 |
Correct |
71 ms |
6528 KB |
Output is correct |
95 |
Correct |
51 ms |
7792 KB |
Output is correct |
96 |
Correct |
72 ms |
7844 KB |
Output is correct |
97 |
Correct |
41 ms |
7900 KB |
Output is correct |
98 |
Correct |
36 ms |
6276 KB |
Output is correct |
99 |
Correct |
41 ms |
6516 KB |
Output is correct |