#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;
struct person {
int x, y, z;
};
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
person v[n];
vector<int> a, b, c;
for (int i = 0; i < n; ++i) {
cin >> v[i].x >> v[i].y >> v[i].z;
a.push_back(i), b.push_back(i), c.push_back(i);
}
sort(all(a), [&](int &i, int &j) {
return v[i].x < v[j].x;
});
sort(all(b), [&](int &i, int &j) {
return v[i].y < v[j].y;
});
sort(all(c), [&](int &i, int &j) {
return v[i].z < v[j].z;
});
while (!a.empty() && !b.empty() && !c.empty()) {
if (v[a.back()].y >= v[b.back()].y || v[a.back()].z >= v[c.back()].z) {
a.pop_back();
continue;
}
if (v[b.back()].x >= v[a.back()].x || v[b.back()].z >= v[c.back()].z) {
b.pop_back();
continue;
}
if (v[c.back()].x >= v[a.back()].x || v[c.back()].y >= v[b.back()].y) {
c.pop_back();
continue;
}
if (a.back() == b.back()) {
if (v[a.back()].x >= v[b.back()].y) {
b.pop_back();
} else {
a.pop_back();
}
} else if (b.back() == c.back()) {
if (v[b.back()].y >= v[c.back()].z) {
c.pop_back();
} else {
b.pop_back();
}
} else if (a.back() == c.back()) {
if (v[a.back()].x >= v[c.back()].z) {
c.pop_back();
} else {
a.pop_back();
}
} else {
cout << v[a.back()].x + v[b.back()].y + v[c.back()].z;
return 0;
}
}
cout << -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
456 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
456 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
856 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
524 KB |
Output is correct |
37 |
Correct |
2 ms |
860 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
39 ms |
9104 KB |
Output is correct |
12 |
Correct |
30 ms |
5824 KB |
Output is correct |
13 |
Correct |
28 ms |
7000 KB |
Output is correct |
14 |
Correct |
36 ms |
8900 KB |
Output is correct |
15 |
Correct |
34 ms |
8900 KB |
Output is correct |
16 |
Correct |
29 ms |
9040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
39 ms |
9104 KB |
Output is correct |
12 |
Correct |
30 ms |
5824 KB |
Output is correct |
13 |
Correct |
28 ms |
7000 KB |
Output is correct |
14 |
Correct |
36 ms |
8900 KB |
Output is correct |
15 |
Correct |
34 ms |
8900 KB |
Output is correct |
16 |
Correct |
29 ms |
9040 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
48 ms |
9296 KB |
Output is correct |
23 |
Correct |
38 ms |
8888 KB |
Output is correct |
24 |
Correct |
33 ms |
6332 KB |
Output is correct |
25 |
Correct |
45 ms |
9272 KB |
Output is correct |
26 |
Correct |
33 ms |
9152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
39 ms |
9104 KB |
Output is correct |
12 |
Correct |
30 ms |
5824 KB |
Output is correct |
13 |
Correct |
28 ms |
7000 KB |
Output is correct |
14 |
Correct |
36 ms |
8900 KB |
Output is correct |
15 |
Correct |
34 ms |
8900 KB |
Output is correct |
16 |
Correct |
29 ms |
9040 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
48 ms |
9296 KB |
Output is correct |
23 |
Correct |
38 ms |
8888 KB |
Output is correct |
24 |
Correct |
33 ms |
6332 KB |
Output is correct |
25 |
Correct |
45 ms |
9272 KB |
Output is correct |
26 |
Correct |
33 ms |
9152 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
49 ms |
9536 KB |
Output is correct |
35 |
Correct |
50 ms |
9148 KB |
Output is correct |
36 |
Correct |
53 ms |
9584 KB |
Output is correct |
37 |
Correct |
53 ms |
9668 KB |
Output is correct |
38 |
Correct |
37 ms |
9668 KB |
Output is correct |
39 |
Correct |
22 ms |
5816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
39 ms |
9104 KB |
Output is correct |
12 |
Correct |
30 ms |
5824 KB |
Output is correct |
13 |
Correct |
28 ms |
7000 KB |
Output is correct |
14 |
Correct |
36 ms |
8900 KB |
Output is correct |
15 |
Correct |
34 ms |
8900 KB |
Output is correct |
16 |
Correct |
29 ms |
9040 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
48 ms |
9296 KB |
Output is correct |
23 |
Correct |
38 ms |
8888 KB |
Output is correct |
24 |
Correct |
33 ms |
6332 KB |
Output is correct |
25 |
Correct |
45 ms |
9272 KB |
Output is correct |
26 |
Correct |
33 ms |
9152 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
49 ms |
9536 KB |
Output is correct |
35 |
Correct |
50 ms |
9148 KB |
Output is correct |
36 |
Correct |
53 ms |
9584 KB |
Output is correct |
37 |
Correct |
53 ms |
9668 KB |
Output is correct |
38 |
Correct |
37 ms |
9668 KB |
Output is correct |
39 |
Correct |
22 ms |
5816 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
728 KB |
Output is correct |
42 |
Correct |
1 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
64 ms |
10432 KB |
Output is correct |
45 |
Correct |
65 ms |
10168 KB |
Output is correct |
46 |
Correct |
63 ms |
10172 KB |
Output is correct |
47 |
Correct |
63 ms |
10184 KB |
Output is correct |
48 |
Correct |
42 ms |
9924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
456 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
856 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
524 KB |
Output is correct |
37 |
Correct |
2 ms |
860 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
452 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
600 KB |
Output is correct |
50 |
Correct |
39 ms |
9104 KB |
Output is correct |
51 |
Correct |
30 ms |
5824 KB |
Output is correct |
52 |
Correct |
28 ms |
7000 KB |
Output is correct |
53 |
Correct |
36 ms |
8900 KB |
Output is correct |
54 |
Correct |
34 ms |
8900 KB |
Output is correct |
55 |
Correct |
29 ms |
9040 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
1 ms |
464 KB |
Output is correct |
61 |
Correct |
48 ms |
9296 KB |
Output is correct |
62 |
Correct |
38 ms |
8888 KB |
Output is correct |
63 |
Correct |
33 ms |
6332 KB |
Output is correct |
64 |
Correct |
45 ms |
9272 KB |
Output is correct |
65 |
Correct |
33 ms |
9152 KB |
Output is correct |
66 |
Correct |
1 ms |
344 KB |
Output is correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
2 ms |
604 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
49 ms |
9536 KB |
Output is correct |
74 |
Correct |
50 ms |
9148 KB |
Output is correct |
75 |
Correct |
53 ms |
9584 KB |
Output is correct |
76 |
Correct |
53 ms |
9668 KB |
Output is correct |
77 |
Correct |
37 ms |
9668 KB |
Output is correct |
78 |
Correct |
22 ms |
5816 KB |
Output is correct |
79 |
Correct |
1 ms |
600 KB |
Output is correct |
80 |
Correct |
2 ms |
728 KB |
Output is correct |
81 |
Correct |
1 ms |
724 KB |
Output is correct |
82 |
Correct |
2 ms |
604 KB |
Output is correct |
83 |
Correct |
64 ms |
10432 KB |
Output is correct |
84 |
Correct |
65 ms |
10168 KB |
Output is correct |
85 |
Correct |
63 ms |
10172 KB |
Output is correct |
86 |
Correct |
63 ms |
10184 KB |
Output is correct |
87 |
Correct |
42 ms |
9924 KB |
Output is correct |
88 |
Correct |
78 ms |
11068 KB |
Output is correct |
89 |
Correct |
82 ms |
11300 KB |
Output is correct |
90 |
Correct |
79 ms |
11312 KB |
Output is correct |
91 |
Correct |
100 ms |
11292 KB |
Output is correct |
92 |
Correct |
73 ms |
10152 KB |
Output is correct |
93 |
Correct |
78 ms |
10240 KB |
Output is correct |
94 |
Correct |
79 ms |
10172 KB |
Output is correct |
95 |
Correct |
52 ms |
10808 KB |
Output is correct |
96 |
Correct |
78 ms |
11164 KB |
Output is correct |
97 |
Correct |
46 ms |
11192 KB |
Output is correct |
98 |
Correct |
39 ms |
10164 KB |
Output is correct |
99 |
Correct |
94 ms |
10160 KB |
Output is correct |