#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
set<pair<int, int>> xx, yy, zz;
int x[n], y[n], z[n];
for(int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> z[i];
xx.insert({x[i], i});
yy.insert({y[i], i});
zz.insert({z[i], i});
}
while(!xx.empty()) {
int pos = (--xx.end())->second;
if(y[pos] == (--yy.end())->first || z[pos] == (--zz.end())->first) {
xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
continue;
}
pos = (--yy.end())->second;
if(x[pos] == (--xx.end())->first || z[pos] == (--zz.end())->first) {
xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
continue;
}
pos = (--zz.end())->second;
if(x[pos] == (--xx.end())->first || y[pos] == (--yy.end())->first) {
xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
continue;
}
cout << (--xx.end())->first + (--yy.end())->first + (--zz.end())->first;
return 0;
}
cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
4 ms |
980 KB |
Output is correct |
29 |
Correct |
4 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
3 ms |
968 KB |
Output is correct |
32 |
Correct |
4 ms |
852 KB |
Output is correct |
33 |
Correct |
4 ms |
968 KB |
Output is correct |
34 |
Correct |
3 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
456 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
852 KB |
Output is correct |
38 |
Correct |
3 ms |
972 KB |
Output is correct |
39 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
118 ms |
24072 KB |
Output is correct |
12 |
Correct |
89 ms |
16152 KB |
Output is correct |
13 |
Correct |
93 ms |
19784 KB |
Output is correct |
14 |
Correct |
162 ms |
24080 KB |
Output is correct |
15 |
Correct |
118 ms |
23988 KB |
Output is correct |
16 |
Correct |
109 ms |
23960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
118 ms |
24072 KB |
Output is correct |
12 |
Correct |
89 ms |
16152 KB |
Output is correct |
13 |
Correct |
93 ms |
19784 KB |
Output is correct |
14 |
Correct |
162 ms |
24080 KB |
Output is correct |
15 |
Correct |
118 ms |
23988 KB |
Output is correct |
16 |
Correct |
109 ms |
23960 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
153 ms |
24196 KB |
Output is correct |
23 |
Correct |
150 ms |
23452 KB |
Output is correct |
24 |
Correct |
122 ms |
17648 KB |
Output is correct |
25 |
Correct |
203 ms |
24268 KB |
Output is correct |
26 |
Correct |
127 ms |
24192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
118 ms |
24072 KB |
Output is correct |
12 |
Correct |
89 ms |
16152 KB |
Output is correct |
13 |
Correct |
93 ms |
19784 KB |
Output is correct |
14 |
Correct |
162 ms |
24080 KB |
Output is correct |
15 |
Correct |
118 ms |
23988 KB |
Output is correct |
16 |
Correct |
109 ms |
23960 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
153 ms |
24196 KB |
Output is correct |
23 |
Correct |
150 ms |
23452 KB |
Output is correct |
24 |
Correct |
122 ms |
17648 KB |
Output is correct |
25 |
Correct |
203 ms |
24268 KB |
Output is correct |
26 |
Correct |
127 ms |
24192 KB |
Output is correct |
27 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
452 KB |
Output is correct |
34 |
Correct |
210 ms |
23628 KB |
Output is correct |
35 |
Correct |
214 ms |
22348 KB |
Output is correct |
36 |
Correct |
271 ms |
24680 KB |
Output is correct |
37 |
Correct |
303 ms |
24612 KB |
Output is correct |
38 |
Correct |
172 ms |
24232 KB |
Output is correct |
39 |
Correct |
72 ms |
14976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
118 ms |
24072 KB |
Output is correct |
12 |
Correct |
89 ms |
16152 KB |
Output is correct |
13 |
Correct |
93 ms |
19784 KB |
Output is correct |
14 |
Correct |
162 ms |
24080 KB |
Output is correct |
15 |
Correct |
118 ms |
23988 KB |
Output is correct |
16 |
Correct |
109 ms |
23960 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
153 ms |
24196 KB |
Output is correct |
23 |
Correct |
150 ms |
23452 KB |
Output is correct |
24 |
Correct |
122 ms |
17648 KB |
Output is correct |
25 |
Correct |
203 ms |
24268 KB |
Output is correct |
26 |
Correct |
127 ms |
24192 KB |
Output is correct |
27 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
452 KB |
Output is correct |
34 |
Correct |
210 ms |
23628 KB |
Output is correct |
35 |
Correct |
214 ms |
22348 KB |
Output is correct |
36 |
Correct |
271 ms |
24680 KB |
Output is correct |
37 |
Correct |
303 ms |
24612 KB |
Output is correct |
38 |
Correct |
172 ms |
24232 KB |
Output is correct |
39 |
Correct |
72 ms |
14976 KB |
Output is correct |
40 |
Correct |
4 ms |
716 KB |
Output is correct |
41 |
Correct |
3 ms |
980 KB |
Output is correct |
42 |
Correct |
2 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
980 KB |
Output is correct |
44 |
Correct |
232 ms |
25212 KB |
Output is correct |
45 |
Correct |
304 ms |
25308 KB |
Output is correct |
46 |
Correct |
298 ms |
25256 KB |
Output is correct |
47 |
Correct |
353 ms |
25328 KB |
Output is correct |
48 |
Correct |
192 ms |
25244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
980 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
4 ms |
980 KB |
Output is correct |
29 |
Correct |
4 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
3 ms |
968 KB |
Output is correct |
32 |
Correct |
4 ms |
852 KB |
Output is correct |
33 |
Correct |
4 ms |
968 KB |
Output is correct |
34 |
Correct |
3 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
456 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
852 KB |
Output is correct |
38 |
Correct |
3 ms |
972 KB |
Output is correct |
39 |
Correct |
1 ms |
588 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
216 KB |
Output is correct |
42 |
Correct |
0 ms |
320 KB |
Output is correct |
43 |
Correct |
0 ms |
216 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
316 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
320 KB |
Output is correct |
48 |
Correct |
0 ms |
320 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
118 ms |
24072 KB |
Output is correct |
51 |
Correct |
89 ms |
16152 KB |
Output is correct |
52 |
Correct |
93 ms |
19784 KB |
Output is correct |
53 |
Correct |
162 ms |
24080 KB |
Output is correct |
54 |
Correct |
118 ms |
23988 KB |
Output is correct |
55 |
Correct |
109 ms |
23960 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
320 KB |
Output is correct |
58 |
Correct |
1 ms |
320 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
596 KB |
Output is correct |
61 |
Correct |
153 ms |
24196 KB |
Output is correct |
62 |
Correct |
150 ms |
23452 KB |
Output is correct |
63 |
Correct |
122 ms |
17648 KB |
Output is correct |
64 |
Correct |
203 ms |
24268 KB |
Output is correct |
65 |
Correct |
127 ms |
24192 KB |
Output is correct |
66 |
Correct |
1 ms |
320 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 |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
452 KB |
Output is correct |
73 |
Correct |
210 ms |
23628 KB |
Output is correct |
74 |
Correct |
214 ms |
22348 KB |
Output is correct |
75 |
Correct |
271 ms |
24680 KB |
Output is correct |
76 |
Correct |
303 ms |
24612 KB |
Output is correct |
77 |
Correct |
172 ms |
24232 KB |
Output is correct |
78 |
Correct |
72 ms |
14976 KB |
Output is correct |
79 |
Correct |
4 ms |
716 KB |
Output is correct |
80 |
Correct |
3 ms |
980 KB |
Output is correct |
81 |
Correct |
2 ms |
852 KB |
Output is correct |
82 |
Correct |
3 ms |
980 KB |
Output is correct |
83 |
Correct |
232 ms |
25212 KB |
Output is correct |
84 |
Correct |
304 ms |
25308 KB |
Output is correct |
85 |
Correct |
298 ms |
25256 KB |
Output is correct |
86 |
Correct |
353 ms |
25328 KB |
Output is correct |
87 |
Correct |
192 ms |
25244 KB |
Output is correct |
88 |
Correct |
255 ms |
27004 KB |
Output is correct |
89 |
Correct |
300 ms |
27092 KB |
Output is correct |
90 |
Correct |
238 ms |
27048 KB |
Output is correct |
91 |
Correct |
275 ms |
27060 KB |
Output is correct |
92 |
Correct |
327 ms |
25624 KB |
Output is correct |
93 |
Correct |
285 ms |
25932 KB |
Output is correct |
94 |
Correct |
337 ms |
25796 KB |
Output is correct |
95 |
Correct |
198 ms |
26976 KB |
Output is correct |
96 |
Correct |
162 ms |
27100 KB |
Output is correct |
97 |
Correct |
122 ms |
27040 KB |
Output is correct |
98 |
Correct |
104 ms |
25676 KB |
Output is correct |
99 |
Correct |
130 ms |
25776 KB |
Output is correct |