#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
const int mxN = (int)1.5e5+10;
struct Coder{ int x, y, z, i; };
vector<Coder> coder;
bool bad[mxN];
int n;
int32_t main() {
cin >> n;
for(int i = 0; i < n; i++){
int x,y,z; cin >>x>>y>>z;
coder.pb({x,y,z,i});
}
sort(all(coder),[&](Coder a, Coder b){
return a.x < b.x;
});
auto coderx = coder;
sort(all(coder),[&](Coder a, Coder b){
return a.y < b.y;
});
auto codery = coder;
sort(all(coder),[&](Coder a, Coder b){
return a.z < b.z;
});
auto coderz = coder;
int i = n-1, j = n-1, k = n-1;
while(1){
while(i>=0 and bad[coderx[i].i]) i--;
while(j>=0 and bad[codery[j].i]) j--;
while(k>=0 and bad[coderz[k].i]) k--;
if(i<0 or j<0 or k<0) {cout<<-1;return 0;}
int X = coderx[i].x, Y = codery[j].y, Z = coderz[k].z;
if(coderx[i].y==Y) bad[coderx[i].i]=1;
if(coderx[i].z==Z) bad[coderx[i].i]=1;
if(codery[j].x==X) bad[codery[j].i]=1;
if(codery[j].z==Z) bad[codery[j].i]=1;
if(coderz[k].x==X) bad[coderz[k].i]=1;
if(coderz[k].y==Y) bad[coderz[k].i]=1;
if(!bad[coderx[i].i] and !bad[codery[j].i] and !bad[coderz[k].i]){
cout << X+Y+Z; return 0;
}
}
}
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 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 |
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 |
312 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
384 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 |
312 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 |
0 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 |
212 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 |
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 |
312 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
384 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 |
312 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 |
6 ms |
892 KB |
Output is correct |
27 |
Correct |
5 ms |
872 KB |
Output is correct |
28 |
Correct |
5 ms |
852 KB |
Output is correct |
29 |
Correct |
6 ms |
832 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
4 ms |
852 KB |
Output is correct |
33 |
Correct |
4 ms |
852 KB |
Output is correct |
34 |
Correct |
5 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
444 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
832 KB |
Output is correct |
38 |
Correct |
4 ms |
756 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
308 KB |
Output is correct |
11 |
Correct |
79 ms |
20020 KB |
Output is correct |
12 |
Correct |
53 ms |
13552 KB |
Output is correct |
13 |
Correct |
80 ms |
16668 KB |
Output is correct |
14 |
Correct |
81 ms |
20140 KB |
Output is correct |
15 |
Correct |
78 ms |
20268 KB |
Output is correct |
16 |
Correct |
81 ms |
20224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
308 KB |
Output is correct |
11 |
Correct |
79 ms |
20020 KB |
Output is correct |
12 |
Correct |
53 ms |
13552 KB |
Output is correct |
13 |
Correct |
80 ms |
16668 KB |
Output is correct |
14 |
Correct |
81 ms |
20140 KB |
Output is correct |
15 |
Correct |
78 ms |
20268 KB |
Output is correct |
16 |
Correct |
81 ms |
20224 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 |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
91 ms |
20284 KB |
Output is correct |
23 |
Correct |
83 ms |
19748 KB |
Output is correct |
24 |
Correct |
72 ms |
14900 KB |
Output is correct |
25 |
Correct |
104 ms |
20416 KB |
Output is correct |
26 |
Correct |
81 ms |
20320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
308 KB |
Output is correct |
11 |
Correct |
79 ms |
20020 KB |
Output is correct |
12 |
Correct |
53 ms |
13552 KB |
Output is correct |
13 |
Correct |
80 ms |
16668 KB |
Output is correct |
14 |
Correct |
81 ms |
20140 KB |
Output is correct |
15 |
Correct |
78 ms |
20268 KB |
Output is correct |
16 |
Correct |
81 ms |
20224 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 |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
91 ms |
20284 KB |
Output is correct |
23 |
Correct |
83 ms |
19748 KB |
Output is correct |
24 |
Correct |
72 ms |
14900 KB |
Output is correct |
25 |
Correct |
104 ms |
20416 KB |
Output is correct |
26 |
Correct |
81 ms |
20320 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 |
308 KB |
Output is correct |
30 |
Correct |
1 ms |
300 KB |
Output is correct |
31 |
Correct |
4 ms |
840 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
106 ms |
19748 KB |
Output is correct |
35 |
Correct |
104 ms |
18984 KB |
Output is correct |
36 |
Correct |
107 ms |
20876 KB |
Output is correct |
37 |
Correct |
116 ms |
20796 KB |
Output is correct |
38 |
Correct |
111 ms |
20476 KB |
Output is correct |
39 |
Correct |
62 ms |
12728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
308 KB |
Output is correct |
11 |
Correct |
79 ms |
20020 KB |
Output is correct |
12 |
Correct |
53 ms |
13552 KB |
Output is correct |
13 |
Correct |
80 ms |
16668 KB |
Output is correct |
14 |
Correct |
81 ms |
20140 KB |
Output is correct |
15 |
Correct |
78 ms |
20268 KB |
Output is correct |
16 |
Correct |
81 ms |
20224 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 |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
91 ms |
20284 KB |
Output is correct |
23 |
Correct |
83 ms |
19748 KB |
Output is correct |
24 |
Correct |
72 ms |
14900 KB |
Output is correct |
25 |
Correct |
104 ms |
20416 KB |
Output is correct |
26 |
Correct |
81 ms |
20320 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 |
308 KB |
Output is correct |
30 |
Correct |
1 ms |
300 KB |
Output is correct |
31 |
Correct |
4 ms |
840 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
106 ms |
19748 KB |
Output is correct |
35 |
Correct |
104 ms |
18984 KB |
Output is correct |
36 |
Correct |
107 ms |
20876 KB |
Output is correct |
37 |
Correct |
116 ms |
20796 KB |
Output is correct |
38 |
Correct |
111 ms |
20476 KB |
Output is correct |
39 |
Correct |
62 ms |
12728 KB |
Output is correct |
40 |
Correct |
3 ms |
596 KB |
Output is correct |
41 |
Correct |
4 ms |
836 KB |
Output is correct |
42 |
Correct |
4 ms |
844 KB |
Output is correct |
43 |
Correct |
3 ms |
852 KB |
Output is correct |
44 |
Correct |
133 ms |
21280 KB |
Output is correct |
45 |
Correct |
142 ms |
21380 KB |
Output is correct |
46 |
Correct |
134 ms |
21400 KB |
Output is correct |
47 |
Correct |
154 ms |
21496 KB |
Output is correct |
48 |
Correct |
124 ms |
21268 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 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 |
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 |
312 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
384 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 |
312 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 |
6 ms |
892 KB |
Output is correct |
27 |
Correct |
5 ms |
872 KB |
Output is correct |
28 |
Correct |
5 ms |
852 KB |
Output is correct |
29 |
Correct |
6 ms |
832 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
4 ms |
852 KB |
Output is correct |
33 |
Correct |
4 ms |
852 KB |
Output is correct |
34 |
Correct |
5 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
444 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
832 KB |
Output is correct |
38 |
Correct |
4 ms |
756 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
312 KB |
Output is correct |
48 |
Correct |
0 ms |
304 KB |
Output is correct |
49 |
Correct |
0 ms |
308 KB |
Output is correct |
50 |
Correct |
79 ms |
20020 KB |
Output is correct |
51 |
Correct |
53 ms |
13552 KB |
Output is correct |
52 |
Correct |
80 ms |
16668 KB |
Output is correct |
53 |
Correct |
81 ms |
20140 KB |
Output is correct |
54 |
Correct |
78 ms |
20268 KB |
Output is correct |
55 |
Correct |
81 ms |
20224 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 |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
596 KB |
Output is correct |
61 |
Correct |
91 ms |
20284 KB |
Output is correct |
62 |
Correct |
83 ms |
19748 KB |
Output is correct |
63 |
Correct |
72 ms |
14900 KB |
Output is correct |
64 |
Correct |
104 ms |
20416 KB |
Output is correct |
65 |
Correct |
81 ms |
20320 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 |
308 KB |
Output is correct |
69 |
Correct |
1 ms |
300 KB |
Output is correct |
70 |
Correct |
4 ms |
840 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
316 KB |
Output is correct |
73 |
Correct |
106 ms |
19748 KB |
Output is correct |
74 |
Correct |
104 ms |
18984 KB |
Output is correct |
75 |
Correct |
107 ms |
20876 KB |
Output is correct |
76 |
Correct |
116 ms |
20796 KB |
Output is correct |
77 |
Correct |
111 ms |
20476 KB |
Output is correct |
78 |
Correct |
62 ms |
12728 KB |
Output is correct |
79 |
Correct |
3 ms |
596 KB |
Output is correct |
80 |
Correct |
4 ms |
836 KB |
Output is correct |
81 |
Correct |
4 ms |
844 KB |
Output is correct |
82 |
Correct |
3 ms |
852 KB |
Output is correct |
83 |
Correct |
133 ms |
21280 KB |
Output is correct |
84 |
Correct |
142 ms |
21380 KB |
Output is correct |
85 |
Correct |
134 ms |
21400 KB |
Output is correct |
86 |
Correct |
154 ms |
21496 KB |
Output is correct |
87 |
Correct |
124 ms |
21268 KB |
Output is correct |
88 |
Correct |
189 ms |
23140 KB |
Output is correct |
89 |
Correct |
215 ms |
23352 KB |
Output is correct |
90 |
Correct |
191 ms |
23288 KB |
Output is correct |
91 |
Correct |
191 ms |
23136 KB |
Output is correct |
92 |
Correct |
148 ms |
21744 KB |
Output is correct |
93 |
Correct |
184 ms |
22100 KB |
Output is correct |
94 |
Correct |
152 ms |
21964 KB |
Output is correct |
95 |
Correct |
170 ms |
23144 KB |
Output is correct |
96 |
Correct |
179 ms |
23228 KB |
Output is correct |
97 |
Correct |
165 ms |
23208 KB |
Output is correct |
98 |
Correct |
125 ms |
21660 KB |
Output is correct |
99 |
Correct |
143 ms |
21868 KB |
Output is correct |