#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct bober {
int x[3];
int num;
};
int n, indexSort=0, ix = 0, iy = 0, iz = 0;
bool tab[150010];
bober tx[150010], ty[150010], tz[150010];
bool sortuj(bober& a, bober& b) {
return a.x[indexSort] > b.x[indexSort];
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tx[i].x[0] >> tx[i].x[1] >> tx[i].x[2];
tx[i].num = i;
ty[i] = tx[i];
tz[i] = tx[i];
}
sort(tx, tx + n, sortuj);
indexSort++;
sort(ty, ty + n, sortuj);
indexSort++;
sort(tz, tz + n, sortuj);
while (ix < n && iy < n && iz < n) {
int maxx = tx[ix].x[0];
int maxy = ty[iy].x[1];
int maxz = tz[iz].x[2];
//cout << tx[ix].num << ' ' << ty[iy].num << ' ' << tz[iz].num << " : " << maxx << ' ' << maxy << ' ' << maxz << '\n';
if (tx[ix].x[1]==maxy||tx[ix].x[2]==maxz) {
tab[tx[ix].num] = true;
ix++;
}
else if (ty[iy].x[0] == maxx || ty[iy].x[2] == maxz) {
tab[ty[iy].num] = true;
iy++;
}
else if (tz[iz].x[1] == maxy || tz[iz].x[0] == maxx) {
tab[tz[iz].num] = true;
iz++;
}
else {
cout << maxx + maxy + maxz << '\n';
return 0;
}
while (ix < n && tab[tx[ix].num] == true) ix++;
while (iy < n && tab[ty[iy].num] == true) iy++;
while (iz < n && tab[tz[iz].num] == true) iz++;
}
cout << -1 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4456 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4456 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4628 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
2 ms |
4440 KB |
Output is correct |
38 |
Correct |
2 ms |
4440 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4564 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
38 ms |
7488 KB |
Output is correct |
12 |
Correct |
25 ms |
6796 KB |
Output is correct |
13 |
Correct |
27 ms |
7004 KB |
Output is correct |
14 |
Correct |
38 ms |
7516 KB |
Output is correct |
15 |
Correct |
34 ms |
7504 KB |
Output is correct |
16 |
Correct |
30 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4564 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
38 ms |
7488 KB |
Output is correct |
12 |
Correct |
25 ms |
6796 KB |
Output is correct |
13 |
Correct |
27 ms |
7004 KB |
Output is correct |
14 |
Correct |
38 ms |
7516 KB |
Output is correct |
15 |
Correct |
34 ms |
7504 KB |
Output is correct |
16 |
Correct |
30 ms |
7512 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4452 KB |
Output is correct |
20 |
Correct |
1 ms |
4452 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
46 ms |
7720 KB |
Output is correct |
23 |
Correct |
39 ms |
7516 KB |
Output is correct |
24 |
Correct |
31 ms |
6748 KB |
Output is correct |
25 |
Correct |
44 ms |
7560 KB |
Output is correct |
26 |
Correct |
36 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4564 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
38 ms |
7488 KB |
Output is correct |
12 |
Correct |
25 ms |
6796 KB |
Output is correct |
13 |
Correct |
27 ms |
7004 KB |
Output is correct |
14 |
Correct |
38 ms |
7516 KB |
Output is correct |
15 |
Correct |
34 ms |
7504 KB |
Output is correct |
16 |
Correct |
30 ms |
7512 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4452 KB |
Output is correct |
20 |
Correct |
1 ms |
4452 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
46 ms |
7720 KB |
Output is correct |
23 |
Correct |
39 ms |
7516 KB |
Output is correct |
24 |
Correct |
31 ms |
6748 KB |
Output is correct |
25 |
Correct |
44 ms |
7560 KB |
Output is correct |
26 |
Correct |
36 ms |
7508 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
54 ms |
7560 KB |
Output is correct |
35 |
Correct |
48 ms |
7260 KB |
Output is correct |
36 |
Correct |
57 ms |
7508 KB |
Output is correct |
37 |
Correct |
53 ms |
7504 KB |
Output is correct |
38 |
Correct |
40 ms |
7516 KB |
Output is correct |
39 |
Correct |
24 ms |
6868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4564 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
38 ms |
7488 KB |
Output is correct |
12 |
Correct |
25 ms |
6796 KB |
Output is correct |
13 |
Correct |
27 ms |
7004 KB |
Output is correct |
14 |
Correct |
38 ms |
7516 KB |
Output is correct |
15 |
Correct |
34 ms |
7504 KB |
Output is correct |
16 |
Correct |
30 ms |
7512 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4452 KB |
Output is correct |
20 |
Correct |
1 ms |
4452 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
46 ms |
7720 KB |
Output is correct |
23 |
Correct |
39 ms |
7516 KB |
Output is correct |
24 |
Correct |
31 ms |
6748 KB |
Output is correct |
25 |
Correct |
44 ms |
7560 KB |
Output is correct |
26 |
Correct |
36 ms |
7508 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
54 ms |
7560 KB |
Output is correct |
35 |
Correct |
48 ms |
7260 KB |
Output is correct |
36 |
Correct |
57 ms |
7508 KB |
Output is correct |
37 |
Correct |
53 ms |
7504 KB |
Output is correct |
38 |
Correct |
40 ms |
7516 KB |
Output is correct |
39 |
Correct |
24 ms |
6868 KB |
Output is correct |
40 |
Correct |
2 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4560 KB |
Output is correct |
42 |
Correct |
2 ms |
4444 KB |
Output is correct |
43 |
Correct |
2 ms |
4444 KB |
Output is correct |
44 |
Correct |
71 ms |
7560 KB |
Output is correct |
45 |
Correct |
63 ms |
7568 KB |
Output is correct |
46 |
Correct |
63 ms |
7484 KB |
Output is correct |
47 |
Correct |
64 ms |
7488 KB |
Output is correct |
48 |
Correct |
45 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4456 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4628 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
2 ms |
4440 KB |
Output is correct |
38 |
Correct |
2 ms |
4440 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
4440 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
1 ms |
4440 KB |
Output is correct |
47 |
Correct |
1 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4564 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
38 ms |
7488 KB |
Output is correct |
51 |
Correct |
25 ms |
6796 KB |
Output is correct |
52 |
Correct |
27 ms |
7004 KB |
Output is correct |
53 |
Correct |
38 ms |
7516 KB |
Output is correct |
54 |
Correct |
34 ms |
7504 KB |
Output is correct |
55 |
Correct |
30 ms |
7512 KB |
Output is correct |
56 |
Correct |
1 ms |
4444 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
58 |
Correct |
1 ms |
4452 KB |
Output is correct |
59 |
Correct |
1 ms |
4452 KB |
Output is correct |
60 |
Correct |
1 ms |
4444 KB |
Output is correct |
61 |
Correct |
46 ms |
7720 KB |
Output is correct |
62 |
Correct |
39 ms |
7516 KB |
Output is correct |
63 |
Correct |
31 ms |
6748 KB |
Output is correct |
64 |
Correct |
44 ms |
7560 KB |
Output is correct |
65 |
Correct |
36 ms |
7508 KB |
Output is correct |
66 |
Correct |
1 ms |
4444 KB |
Output is correct |
67 |
Correct |
1 ms |
4444 KB |
Output is correct |
68 |
Correct |
1 ms |
4444 KB |
Output is correct |
69 |
Correct |
1 ms |
4444 KB |
Output is correct |
70 |
Correct |
3 ms |
4444 KB |
Output is correct |
71 |
Correct |
1 ms |
4444 KB |
Output is correct |
72 |
Correct |
1 ms |
4444 KB |
Output is correct |
73 |
Correct |
54 ms |
7560 KB |
Output is correct |
74 |
Correct |
48 ms |
7260 KB |
Output is correct |
75 |
Correct |
57 ms |
7508 KB |
Output is correct |
76 |
Correct |
53 ms |
7504 KB |
Output is correct |
77 |
Correct |
40 ms |
7516 KB |
Output is correct |
78 |
Correct |
24 ms |
6868 KB |
Output is correct |
79 |
Correct |
2 ms |
4444 KB |
Output is correct |
80 |
Correct |
2 ms |
4560 KB |
Output is correct |
81 |
Correct |
2 ms |
4444 KB |
Output is correct |
82 |
Correct |
2 ms |
4444 KB |
Output is correct |
83 |
Correct |
71 ms |
7560 KB |
Output is correct |
84 |
Correct |
63 ms |
7568 KB |
Output is correct |
85 |
Correct |
63 ms |
7484 KB |
Output is correct |
86 |
Correct |
64 ms |
7488 KB |
Output is correct |
87 |
Correct |
45 ms |
7508 KB |
Output is correct |
88 |
Correct |
77 ms |
7252 KB |
Output is correct |
89 |
Correct |
82 ms |
7492 KB |
Output is correct |
90 |
Correct |
78 ms |
7504 KB |
Output is correct |
91 |
Correct |
82 ms |
7560 KB |
Output is correct |
92 |
Correct |
72 ms |
7484 KB |
Output is correct |
93 |
Correct |
77 ms |
7488 KB |
Output is correct |
94 |
Correct |
79 ms |
7504 KB |
Output is correct |
95 |
Correct |
53 ms |
7504 KB |
Output is correct |
96 |
Correct |
78 ms |
7504 KB |
Output is correct |
97 |
Correct |
43 ms |
7396 KB |
Output is correct |
98 |
Correct |
42 ms |
7260 KB |
Output is correct |
99 |
Correct |
46 ms |
7508 KB |
Output is correct |