#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 3>> x(n);
for (auto &[a, b, c] : x) {
cin >> a >> b >> c;
}
auto y = x;
auto z = x;
sort(begin(x), end(x), [&](auto a, auto b) {
return a[0] < b[0];
});
sort(begin(y), end(y), [&](auto a, auto b) {
return a[1] < b[1];
});
sort(begin(z), end(z), [&](auto a, auto b) {
return a[2] < b[2];
});
while (!x.empty() && !y.empty() && !z.empty()) {
if (x.back()[1] >= y.back()[1] || x.back()[2] >= z.back()[2]) {
x.pop_back();
continue;
}
if (y.back()[0] >= x.back()[0] || y.back()[2] >= z.back()[2]) {
y.pop_back();
continue;
}
if (z.back()[0] >= x.back()[0] || z.back()[1] >= y.back()[1]) {
z.pop_back();
continue;
}
break;
}
if (x.empty() || y.empty() || z.empty()) {
cout << "-1\n";
} else {
cout << x.back()[0] + y.back()[1] + z.back()[2] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
456 KB |
Output is correct |
29 |
Correct |
3 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
372 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
428 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
456 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
6016 KB |
Output is correct |
12 |
Correct |
27 ms |
4220 KB |
Output is correct |
13 |
Correct |
28 ms |
5332 KB |
Output is correct |
14 |
Correct |
38 ms |
6348 KB |
Output is correct |
15 |
Correct |
35 ms |
5988 KB |
Output is correct |
16 |
Correct |
33 ms |
6132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
6016 KB |
Output is correct |
12 |
Correct |
27 ms |
4220 KB |
Output is correct |
13 |
Correct |
28 ms |
5332 KB |
Output is correct |
14 |
Correct |
38 ms |
6348 KB |
Output is correct |
15 |
Correct |
35 ms |
5988 KB |
Output is correct |
16 |
Correct |
33 ms |
6132 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
49 ms |
6284 KB |
Output is correct |
23 |
Correct |
41 ms |
6296 KB |
Output is correct |
24 |
Correct |
34 ms |
4732 KB |
Output is correct |
25 |
Correct |
48 ms |
6636 KB |
Output is correct |
26 |
Correct |
39 ms |
6500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
6016 KB |
Output is correct |
12 |
Correct |
27 ms |
4220 KB |
Output is correct |
13 |
Correct |
28 ms |
5332 KB |
Output is correct |
14 |
Correct |
38 ms |
6348 KB |
Output is correct |
15 |
Correct |
35 ms |
5988 KB |
Output is correct |
16 |
Correct |
33 ms |
6132 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
49 ms |
6284 KB |
Output is correct |
23 |
Correct |
41 ms |
6296 KB |
Output is correct |
24 |
Correct |
34 ms |
4732 KB |
Output is correct |
25 |
Correct |
48 ms |
6636 KB |
Output is correct |
26 |
Correct |
39 ms |
6500 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
456 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
53 ms |
6696 KB |
Output is correct |
35 |
Correct |
52 ms |
6028 KB |
Output is correct |
36 |
Correct |
58 ms |
6604 KB |
Output is correct |
37 |
Correct |
56 ms |
7204 KB |
Output is correct |
38 |
Correct |
51 ms |
6516 KB |
Output is correct |
39 |
Correct |
26 ms |
4084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
39 ms |
6016 KB |
Output is correct |
12 |
Correct |
27 ms |
4220 KB |
Output is correct |
13 |
Correct |
28 ms |
5332 KB |
Output is correct |
14 |
Correct |
38 ms |
6348 KB |
Output is correct |
15 |
Correct |
35 ms |
5988 KB |
Output is correct |
16 |
Correct |
33 ms |
6132 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
49 ms |
6284 KB |
Output is correct |
23 |
Correct |
41 ms |
6296 KB |
Output is correct |
24 |
Correct |
34 ms |
4732 KB |
Output is correct |
25 |
Correct |
48 ms |
6636 KB |
Output is correct |
26 |
Correct |
39 ms |
6500 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
456 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
53 ms |
6696 KB |
Output is correct |
35 |
Correct |
52 ms |
6028 KB |
Output is correct |
36 |
Correct |
58 ms |
6604 KB |
Output is correct |
37 |
Correct |
56 ms |
7204 KB |
Output is correct |
38 |
Correct |
51 ms |
6516 KB |
Output is correct |
39 |
Correct |
26 ms |
4084 KB |
Output is correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
456 KB |
Output is correct |
43 |
Correct |
3 ms |
464 KB |
Output is correct |
44 |
Correct |
64 ms |
7484 KB |
Output is correct |
45 |
Correct |
66 ms |
7632 KB |
Output is correct |
46 |
Correct |
63 ms |
7008 KB |
Output is correct |
47 |
Correct |
66 ms |
7628 KB |
Output is correct |
48 |
Correct |
50 ms |
7444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
456 KB |
Output is correct |
29 |
Correct |
3 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
372 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
428 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
456 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 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 |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
316 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
39 ms |
6016 KB |
Output is correct |
51 |
Correct |
27 ms |
4220 KB |
Output is correct |
52 |
Correct |
28 ms |
5332 KB |
Output is correct |
53 |
Correct |
38 ms |
6348 KB |
Output is correct |
54 |
Correct |
35 ms |
5988 KB |
Output is correct |
55 |
Correct |
33 ms |
6132 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
316 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
49 ms |
6284 KB |
Output is correct |
62 |
Correct |
41 ms |
6296 KB |
Output is correct |
63 |
Correct |
34 ms |
4732 KB |
Output is correct |
64 |
Correct |
48 ms |
6636 KB |
Output is correct |
65 |
Correct |
39 ms |
6500 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
1 ms |
212 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
212 KB |
Output is correct |
70 |
Correct |
3 ms |
456 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
53 ms |
6696 KB |
Output is correct |
74 |
Correct |
52 ms |
6028 KB |
Output is correct |
75 |
Correct |
58 ms |
6604 KB |
Output is correct |
76 |
Correct |
56 ms |
7204 KB |
Output is correct |
77 |
Correct |
51 ms |
6516 KB |
Output is correct |
78 |
Correct |
26 ms |
4084 KB |
Output is correct |
79 |
Correct |
2 ms |
384 KB |
Output is correct |
80 |
Correct |
2 ms |
460 KB |
Output is correct |
81 |
Correct |
1 ms |
456 KB |
Output is correct |
82 |
Correct |
3 ms |
464 KB |
Output is correct |
83 |
Correct |
64 ms |
7484 KB |
Output is correct |
84 |
Correct |
66 ms |
7632 KB |
Output is correct |
85 |
Correct |
63 ms |
7008 KB |
Output is correct |
86 |
Correct |
66 ms |
7628 KB |
Output is correct |
87 |
Correct |
50 ms |
7444 KB |
Output is correct |
88 |
Correct |
81 ms |
8040 KB |
Output is correct |
89 |
Correct |
85 ms |
7612 KB |
Output is correct |
90 |
Correct |
81 ms |
9420 KB |
Output is correct |
91 |
Correct |
86 ms |
7260 KB |
Output is correct |
92 |
Correct |
76 ms |
7116 KB |
Output is correct |
93 |
Correct |
78 ms |
8356 KB |
Output is correct |
94 |
Correct |
79 ms |
8084 KB |
Output is correct |
95 |
Correct |
64 ms |
9384 KB |
Output is correct |
96 |
Correct |
85 ms |
9104 KB |
Output is correct |
97 |
Correct |
54 ms |
8168 KB |
Output is correct |
98 |
Correct |
43 ms |
8012 KB |
Output is correct |
99 |
Correct |
86 ms |
8020 KB |
Output is correct |