#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
void testCase() {
int n;
cin >> n;
vector<int> x(n), y(n), z(n);
for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
set<pair<int, int>> s1, s2, s3;
for (int i = 0; i < n; i++) {
s1.insert({x[i], i});
s2.insert({y[i], i});
s3.insert({z[i], i});
}
int ans = -1;
auto erase = [&](int i) {
s1.erase({x[i], i});
s2.erase({y[i], i});
s3.erase({z[i], i});
return 1;
};
while (!s1.empty()) {
auto [a, i] = *s1.rbegin();
auto [b, j] = *s2.rbegin();
auto [c, k] = *s3.rbegin();
if (z[i] == c || y[i] == b) {
erase(i);
continue;
}
if (z[j] == c || x[j] == a) {
erase(j);
continue;
}
if (x[k] == a || y[k] == b) {
erase(k);
continue;
}
break;
}
if (s1.empty()) cout << ans << "\n";
else {
auto [a, i] = *s1.rbegin();
auto [b, j] = *s2.rbegin();
auto [c, k] = *s3.rbegin();
cout << a + b + c << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
980 KB |
Output is correct |
27 |
Correct |
5 ms |
972 KB |
Output is correct |
28 |
Correct |
5 ms |
980 KB |
Output is correct |
29 |
Correct |
6 ms |
992 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
980 KB |
Output is correct |
32 |
Correct |
5 ms |
980 KB |
Output is correct |
33 |
Correct |
4 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
456 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
972 KB |
Output is correct |
38 |
Correct |
3 ms |
980 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24080 KB |
Output is correct |
12 |
Correct |
122 ms |
16076 KB |
Output is correct |
13 |
Correct |
122 ms |
19884 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
141 ms |
24096 KB |
Output is correct |
16 |
Correct |
147 ms |
24084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24080 KB |
Output is correct |
12 |
Correct |
122 ms |
16076 KB |
Output is correct |
13 |
Correct |
122 ms |
19884 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
141 ms |
24096 KB |
Output is correct |
16 |
Correct |
147 ms |
24084 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
184 ms |
24260 KB |
Output is correct |
23 |
Correct |
217 ms |
23580 KB |
Output is correct |
24 |
Correct |
188 ms |
17596 KB |
Output is correct |
25 |
Correct |
267 ms |
24316 KB |
Output is correct |
26 |
Correct |
176 ms |
24144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24080 KB |
Output is correct |
12 |
Correct |
122 ms |
16076 KB |
Output is correct |
13 |
Correct |
122 ms |
19884 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
141 ms |
24096 KB |
Output is correct |
16 |
Correct |
147 ms |
24084 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
184 ms |
24260 KB |
Output is correct |
23 |
Correct |
217 ms |
23580 KB |
Output is correct |
24 |
Correct |
188 ms |
17596 KB |
Output is correct |
25 |
Correct |
267 ms |
24316 KB |
Output is correct |
26 |
Correct |
176 ms |
24144 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 |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
852 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
230 ms |
23712 KB |
Output is correct |
35 |
Correct |
287 ms |
22560 KB |
Output is correct |
36 |
Correct |
302 ms |
24712 KB |
Output is correct |
37 |
Correct |
358 ms |
24684 KB |
Output is correct |
38 |
Correct |
184 ms |
24184 KB |
Output is correct |
39 |
Correct |
85 ms |
14924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24080 KB |
Output is correct |
12 |
Correct |
122 ms |
16076 KB |
Output is correct |
13 |
Correct |
122 ms |
19884 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
141 ms |
24096 KB |
Output is correct |
16 |
Correct |
147 ms |
24084 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
184 ms |
24260 KB |
Output is correct |
23 |
Correct |
217 ms |
23580 KB |
Output is correct |
24 |
Correct |
188 ms |
17596 KB |
Output is correct |
25 |
Correct |
267 ms |
24316 KB |
Output is correct |
26 |
Correct |
176 ms |
24144 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 |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
852 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
230 ms |
23712 KB |
Output is correct |
35 |
Correct |
287 ms |
22560 KB |
Output is correct |
36 |
Correct |
302 ms |
24712 KB |
Output is correct |
37 |
Correct |
358 ms |
24684 KB |
Output is correct |
38 |
Correct |
184 ms |
24184 KB |
Output is correct |
39 |
Correct |
85 ms |
14924 KB |
Output is correct |
40 |
Correct |
3 ms |
724 KB |
Output is correct |
41 |
Correct |
3 ms |
980 KB |
Output is correct |
42 |
Correct |
3 ms |
980 KB |
Output is correct |
43 |
Correct |
3 ms |
928 KB |
Output is correct |
44 |
Correct |
348 ms |
25296 KB |
Output is correct |
45 |
Correct |
417 ms |
25344 KB |
Output is correct |
46 |
Correct |
404 ms |
25280 KB |
Output is correct |
47 |
Correct |
428 ms |
25364 KB |
Output is correct |
48 |
Correct |
239 ms |
25352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
980 KB |
Output is correct |
27 |
Correct |
5 ms |
972 KB |
Output is correct |
28 |
Correct |
5 ms |
980 KB |
Output is correct |
29 |
Correct |
6 ms |
992 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
980 KB |
Output is correct |
32 |
Correct |
5 ms |
980 KB |
Output is correct |
33 |
Correct |
4 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
456 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
972 KB |
Output is correct |
38 |
Correct |
3 ms |
980 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
316 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
316 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
166 ms |
24080 KB |
Output is correct |
51 |
Correct |
122 ms |
16076 KB |
Output is correct |
52 |
Correct |
122 ms |
19884 KB |
Output is correct |
53 |
Correct |
196 ms |
24012 KB |
Output is correct |
54 |
Correct |
141 ms |
24096 KB |
Output is correct |
55 |
Correct |
147 ms |
24084 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
312 KB |
Output is correct |
60 |
Correct |
2 ms |
588 KB |
Output is correct |
61 |
Correct |
184 ms |
24260 KB |
Output is correct |
62 |
Correct |
217 ms |
23580 KB |
Output is correct |
63 |
Correct |
188 ms |
17596 KB |
Output is correct |
64 |
Correct |
267 ms |
24316 KB |
Output is correct |
65 |
Correct |
176 ms |
24144 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 |
340 KB |
Output is correct |
70 |
Correct |
5 ms |
852 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
468 KB |
Output is correct |
73 |
Correct |
230 ms |
23712 KB |
Output is correct |
74 |
Correct |
287 ms |
22560 KB |
Output is correct |
75 |
Correct |
302 ms |
24712 KB |
Output is correct |
76 |
Correct |
358 ms |
24684 KB |
Output is correct |
77 |
Correct |
184 ms |
24184 KB |
Output is correct |
78 |
Correct |
85 ms |
14924 KB |
Output is correct |
79 |
Correct |
3 ms |
724 KB |
Output is correct |
80 |
Correct |
3 ms |
980 KB |
Output is correct |
81 |
Correct |
3 ms |
980 KB |
Output is correct |
82 |
Correct |
3 ms |
928 KB |
Output is correct |
83 |
Correct |
348 ms |
25296 KB |
Output is correct |
84 |
Correct |
417 ms |
25344 KB |
Output is correct |
85 |
Correct |
404 ms |
25280 KB |
Output is correct |
86 |
Correct |
428 ms |
25364 KB |
Output is correct |
87 |
Correct |
239 ms |
25352 KB |
Output is correct |
88 |
Correct |
361 ms |
27032 KB |
Output is correct |
89 |
Correct |
350 ms |
27076 KB |
Output is correct |
90 |
Correct |
326 ms |
27068 KB |
Output is correct |
91 |
Correct |
370 ms |
27160 KB |
Output is correct |
92 |
Correct |
380 ms |
25636 KB |
Output is correct |
93 |
Correct |
382 ms |
25948 KB |
Output is correct |
94 |
Correct |
430 ms |
25744 KB |
Output is correct |
95 |
Correct |
249 ms |
27004 KB |
Output is correct |
96 |
Correct |
196 ms |
27132 KB |
Output is correct |
97 |
Correct |
158 ms |
27180 KB |
Output is correct |
98 |
Correct |
127 ms |
25744 KB |
Output is correct |
99 |
Correct |
154 ms |
25760 KB |
Output is correct |