#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500025;
int n, a[MAXN], b[MAXN], c[MAXN];
vector <int> ind[3];
bool ok[MAXN];
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i] >> c[i];
ok[i] = 1;
for (int j = 0; j < 3; j++) ind[j].push_back(i);
}
sort(ind[0].begin(), ind[0].end(), [&] (int x, int y) {
return a[x] < a[y];
});
sort(ind[1].begin(), ind[1].end(), [&] (int x, int y) {
return b[x] < b[y];
});
sort(ind[2].begin(), ind[2].end(), [&] (int x, int y) {
return c[x] < c[y];
});
while (!(ind[0].empty() || ind[1].empty() || ind[2].empty())) {
int x = ind[0].back(), y = ind[1].back(), z = ind[2].back();
if (b[x] == b[y] || c[x] == c[z]) ok[x] = 0;
if (a[y] == a[x] || c[y] == c[z]) ok[y] = 0;
if (a[z] == a[x] || b[z] == b[y]) ok[z] = 0;
if (ok[x] && ok[y] && ok[z]) {
cout << a[x] + b[y] + c[z] << '\n';
return 0;
}
while (!ind[0].empty() && !ok[ind[0].back()]) ind[0].pop_back();
while (!ind[1].empty() && !ok[ind[1].back()]) ind[1].pop_back();
while (!ind[2].empty() && !ok[ind[2].back()]) ind[2].pop_back();
}
cout << "-1\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6612 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6628 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6612 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6628 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6612 KB |
Output is correct |
26 |
Correct |
3 ms |
6744 KB |
Output is correct |
27 |
Correct |
3 ms |
6744 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
3 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6684 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
3 ms |
6744 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
3 ms |
6620 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
29 ms |
8940 KB |
Output is correct |
12 |
Correct |
21 ms |
7888 KB |
Output is correct |
13 |
Correct |
22 ms |
8912 KB |
Output is correct |
14 |
Correct |
32 ms |
9776 KB |
Output is correct |
15 |
Correct |
32 ms |
9824 KB |
Output is correct |
16 |
Correct |
25 ms |
9824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
29 ms |
8940 KB |
Output is correct |
12 |
Correct |
21 ms |
7888 KB |
Output is correct |
13 |
Correct |
22 ms |
8912 KB |
Output is correct |
14 |
Correct |
32 ms |
9776 KB |
Output is correct |
15 |
Correct |
32 ms |
9824 KB |
Output is correct |
16 |
Correct |
25 ms |
9824 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6580 KB |
Output is correct |
21 |
Correct |
1 ms |
6500 KB |
Output is correct |
22 |
Correct |
39 ms |
9940 KB |
Output is correct |
23 |
Correct |
33 ms |
9680 KB |
Output is correct |
24 |
Correct |
27 ms |
8908 KB |
Output is correct |
25 |
Correct |
38 ms |
9924 KB |
Output is correct |
26 |
Correct |
30 ms |
9924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
29 ms |
8940 KB |
Output is correct |
12 |
Correct |
21 ms |
7888 KB |
Output is correct |
13 |
Correct |
22 ms |
8912 KB |
Output is correct |
14 |
Correct |
32 ms |
9776 KB |
Output is correct |
15 |
Correct |
32 ms |
9824 KB |
Output is correct |
16 |
Correct |
25 ms |
9824 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6580 KB |
Output is correct |
21 |
Correct |
1 ms |
6500 KB |
Output is correct |
22 |
Correct |
39 ms |
9940 KB |
Output is correct |
23 |
Correct |
33 ms |
9680 KB |
Output is correct |
24 |
Correct |
27 ms |
8908 KB |
Output is correct |
25 |
Correct |
38 ms |
9924 KB |
Output is correct |
26 |
Correct |
30 ms |
9924 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
45 ms |
10448 KB |
Output is correct |
35 |
Correct |
43 ms |
10168 KB |
Output is correct |
36 |
Correct |
46 ms |
10372 KB |
Output is correct |
37 |
Correct |
49 ms |
10448 KB |
Output is correct |
38 |
Correct |
35 ms |
10404 KB |
Output is correct |
39 |
Correct |
20 ms |
8664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
29 ms |
8940 KB |
Output is correct |
12 |
Correct |
21 ms |
7888 KB |
Output is correct |
13 |
Correct |
22 ms |
8912 KB |
Output is correct |
14 |
Correct |
32 ms |
9776 KB |
Output is correct |
15 |
Correct |
32 ms |
9824 KB |
Output is correct |
16 |
Correct |
25 ms |
9824 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6580 KB |
Output is correct |
21 |
Correct |
1 ms |
6500 KB |
Output is correct |
22 |
Correct |
39 ms |
9940 KB |
Output is correct |
23 |
Correct |
33 ms |
9680 KB |
Output is correct |
24 |
Correct |
27 ms |
8908 KB |
Output is correct |
25 |
Correct |
38 ms |
9924 KB |
Output is correct |
26 |
Correct |
30 ms |
9924 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
45 ms |
10448 KB |
Output is correct |
35 |
Correct |
43 ms |
10168 KB |
Output is correct |
36 |
Correct |
46 ms |
10372 KB |
Output is correct |
37 |
Correct |
49 ms |
10448 KB |
Output is correct |
38 |
Correct |
35 ms |
10404 KB |
Output is correct |
39 |
Correct |
20 ms |
8664 KB |
Output is correct |
40 |
Correct |
2 ms |
6492 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6704 KB |
Output is correct |
44 |
Correct |
56 ms |
10800 KB |
Output is correct |
45 |
Correct |
58 ms |
10956 KB |
Output is correct |
46 |
Correct |
58 ms |
10996 KB |
Output is correct |
47 |
Correct |
59 ms |
10952 KB |
Output is correct |
48 |
Correct |
47 ms |
10820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6612 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6628 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6612 KB |
Output is correct |
26 |
Correct |
3 ms |
6744 KB |
Output is correct |
27 |
Correct |
3 ms |
6744 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
3 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6684 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
3 ms |
6744 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
3 ms |
6620 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
1 ms |
6492 KB |
Output is correct |
42 |
Correct |
1 ms |
6492 KB |
Output is correct |
43 |
Correct |
1 ms |
6492 KB |
Output is correct |
44 |
Correct |
1 ms |
6492 KB |
Output is correct |
45 |
Correct |
1 ms |
6492 KB |
Output is correct |
46 |
Correct |
1 ms |
6492 KB |
Output is correct |
47 |
Correct |
1 ms |
6492 KB |
Output is correct |
48 |
Correct |
1 ms |
6492 KB |
Output is correct |
49 |
Correct |
1 ms |
6492 KB |
Output is correct |
50 |
Correct |
29 ms |
8940 KB |
Output is correct |
51 |
Correct |
21 ms |
7888 KB |
Output is correct |
52 |
Correct |
22 ms |
8912 KB |
Output is correct |
53 |
Correct |
32 ms |
9776 KB |
Output is correct |
54 |
Correct |
32 ms |
9824 KB |
Output is correct |
55 |
Correct |
25 ms |
9824 KB |
Output is correct |
56 |
Correct |
1 ms |
6492 KB |
Output is correct |
57 |
Correct |
1 ms |
6492 KB |
Output is correct |
58 |
Correct |
1 ms |
6492 KB |
Output is correct |
59 |
Correct |
1 ms |
6580 KB |
Output is correct |
60 |
Correct |
1 ms |
6500 KB |
Output is correct |
61 |
Correct |
39 ms |
9940 KB |
Output is correct |
62 |
Correct |
33 ms |
9680 KB |
Output is correct |
63 |
Correct |
27 ms |
8908 KB |
Output is correct |
64 |
Correct |
38 ms |
9924 KB |
Output is correct |
65 |
Correct |
30 ms |
9924 KB |
Output is correct |
66 |
Correct |
1 ms |
6492 KB |
Output is correct |
67 |
Correct |
1 ms |
6492 KB |
Output is correct |
68 |
Correct |
1 ms |
6492 KB |
Output is correct |
69 |
Correct |
1 ms |
6492 KB |
Output is correct |
70 |
Correct |
3 ms |
6492 KB |
Output is correct |
71 |
Correct |
1 ms |
6492 KB |
Output is correct |
72 |
Correct |
2 ms |
6488 KB |
Output is correct |
73 |
Correct |
45 ms |
10448 KB |
Output is correct |
74 |
Correct |
43 ms |
10168 KB |
Output is correct |
75 |
Correct |
46 ms |
10372 KB |
Output is correct |
76 |
Correct |
49 ms |
10448 KB |
Output is correct |
77 |
Correct |
35 ms |
10404 KB |
Output is correct |
78 |
Correct |
20 ms |
8664 KB |
Output is correct |
79 |
Correct |
2 ms |
6492 KB |
Output is correct |
80 |
Correct |
2 ms |
6492 KB |
Output is correct |
81 |
Correct |
2 ms |
6492 KB |
Output is correct |
82 |
Correct |
2 ms |
6704 KB |
Output is correct |
83 |
Correct |
56 ms |
10800 KB |
Output is correct |
84 |
Correct |
58 ms |
10956 KB |
Output is correct |
85 |
Correct |
58 ms |
10996 KB |
Output is correct |
86 |
Correct |
59 ms |
10952 KB |
Output is correct |
87 |
Correct |
47 ms |
10820 KB |
Output is correct |
88 |
Correct |
70 ms |
12484 KB |
Output is correct |
89 |
Correct |
74 ms |
12488 KB |
Output is correct |
90 |
Correct |
72 ms |
12348 KB |
Output is correct |
91 |
Correct |
76 ms |
12516 KB |
Output is correct |
92 |
Correct |
72 ms |
11208 KB |
Output is correct |
93 |
Correct |
71 ms |
11460 KB |
Output is correct |
94 |
Correct |
69 ms |
11204 KB |
Output is correct |
95 |
Correct |
49 ms |
12228 KB |
Output is correct |
96 |
Correct |
71 ms |
12488 KB |
Output is correct |
97 |
Correct |
41 ms |
12488 KB |
Output is correct |
98 |
Correct |
35 ms |
11208 KB |
Output is correct |
99 |
Correct |
81 ms |
11216 KB |
Output is correct |