#include <bits/stdc++.h>
#define val first
#define id second
#define pii pair<ll, ll>
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1e15;
using namespace std;
ll n, tmpx[150010], tmpy[150010], tmpz[150010];
vector<pii> x, y, z;
bool vis[150010];
int main() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> tmpx[i] >> tmpy[i] >> tmpz[i];
x.push_back({tmpx[i], i});
y.push_back({tmpy[i], i});
z.push_back({tmpz[i], i});
vis[i] = 1;
}
sort(x.begin(), x.end());
sort(y.begin(), y.end());
sort(z.begin(), z.end());
while (!x.empty() && !y.empty() && !z.empty()) {
if (y.back().val == tmpy[x.back().id] || z.back().val == tmpz[x.back().id]) {
vis[x.back().id] = 0;
}
else if (x.back().val == tmpx[y.back().id] || z.back().val == tmpz[y.back().id]) {
vis[y.back().id] = 0;
}
else if (x.back().val == tmpx[z.back().id] || y.back().val == tmpy[z.back().id]) {
vis[z.back().id] = 0;
}
else {
cout << x.back().val+y.back().val+z.back().val << "\n";
return 0;
}
while (!x.empty() && !vis[x.back().id]) x.pop_back();
while (!y.empty() && !vis[y.back().id]) y.pop_back();
while (!z.empty() && !vis[z.back().id]) z.pop_back();
}
cout << "-1\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2528 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2528 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2788 KB |
Output is correct |
27 |
Correct |
3 ms |
2908 KB |
Output is correct |
28 |
Correct |
2 ms |
2908 KB |
Output is correct |
29 |
Correct |
2 ms |
2908 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2788 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
2904 KB |
Output is correct |
34 |
Correct |
3 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2532 KB |
Output is correct |
37 |
Correct |
2 ms |
2784 KB |
Output is correct |
38 |
Correct |
2 ms |
2908 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
60 ms |
15016 KB |
Output is correct |
12 |
Correct |
41 ms |
8632 KB |
Output is correct |
13 |
Correct |
43 ms |
10320 KB |
Output is correct |
14 |
Correct |
62 ms |
16036 KB |
Output is correct |
15 |
Correct |
56 ms |
15020 KB |
Output is correct |
16 |
Correct |
38 ms |
15276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
60 ms |
15016 KB |
Output is correct |
12 |
Correct |
41 ms |
8632 KB |
Output is correct |
13 |
Correct |
43 ms |
10320 KB |
Output is correct |
14 |
Correct |
62 ms |
16036 KB |
Output is correct |
15 |
Correct |
56 ms |
15020 KB |
Output is correct |
16 |
Correct |
38 ms |
15276 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
67 ms |
15096 KB |
Output is correct |
23 |
Correct |
64 ms |
14004 KB |
Output is correct |
24 |
Correct |
48 ms |
9388 KB |
Output is correct |
25 |
Correct |
69 ms |
15268 KB |
Output is correct |
26 |
Correct |
60 ms |
18600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
60 ms |
15016 KB |
Output is correct |
12 |
Correct |
41 ms |
8632 KB |
Output is correct |
13 |
Correct |
43 ms |
10320 KB |
Output is correct |
14 |
Correct |
62 ms |
16036 KB |
Output is correct |
15 |
Correct |
56 ms |
15020 KB |
Output is correct |
16 |
Correct |
38 ms |
15276 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
67 ms |
15096 KB |
Output is correct |
23 |
Correct |
64 ms |
14004 KB |
Output is correct |
24 |
Correct |
48 ms |
9388 KB |
Output is correct |
25 |
Correct |
69 ms |
15268 KB |
Output is correct |
26 |
Correct |
60 ms |
18600 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
72 ms |
18004 KB |
Output is correct |
35 |
Correct |
66 ms |
17584 KB |
Output is correct |
36 |
Correct |
70 ms |
14492 KB |
Output is correct |
37 |
Correct |
72 ms |
16044 KB |
Output is correct |
38 |
Correct |
58 ms |
15792 KB |
Output is correct |
39 |
Correct |
28 ms |
8628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
60 ms |
15016 KB |
Output is correct |
12 |
Correct |
41 ms |
8632 KB |
Output is correct |
13 |
Correct |
43 ms |
10320 KB |
Output is correct |
14 |
Correct |
62 ms |
16036 KB |
Output is correct |
15 |
Correct |
56 ms |
15020 KB |
Output is correct |
16 |
Correct |
38 ms |
15276 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
67 ms |
15096 KB |
Output is correct |
23 |
Correct |
64 ms |
14004 KB |
Output is correct |
24 |
Correct |
48 ms |
9388 KB |
Output is correct |
25 |
Correct |
69 ms |
15268 KB |
Output is correct |
26 |
Correct |
60 ms |
18600 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
72 ms |
18004 KB |
Output is correct |
35 |
Correct |
66 ms |
17584 KB |
Output is correct |
36 |
Correct |
70 ms |
14492 KB |
Output is correct |
37 |
Correct |
72 ms |
16044 KB |
Output is correct |
38 |
Correct |
58 ms |
15792 KB |
Output is correct |
39 |
Correct |
28 ms |
8628 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2784 KB |
Output is correct |
43 |
Correct |
3 ms |
2784 KB |
Output is correct |
44 |
Correct |
79 ms |
17576 KB |
Output is correct |
45 |
Correct |
76 ms |
16008 KB |
Output is correct |
46 |
Correct |
75 ms |
16728 KB |
Output is correct |
47 |
Correct |
80 ms |
18584 KB |
Output is correct |
48 |
Correct |
70 ms |
17828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2528 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2788 KB |
Output is correct |
27 |
Correct |
3 ms |
2908 KB |
Output is correct |
28 |
Correct |
2 ms |
2908 KB |
Output is correct |
29 |
Correct |
2 ms |
2908 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2788 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
2904 KB |
Output is correct |
34 |
Correct |
3 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2532 KB |
Output is correct |
37 |
Correct |
2 ms |
2784 KB |
Output is correct |
38 |
Correct |
2 ms |
2908 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2392 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
60 ms |
15016 KB |
Output is correct |
51 |
Correct |
41 ms |
8632 KB |
Output is correct |
52 |
Correct |
43 ms |
10320 KB |
Output is correct |
53 |
Correct |
62 ms |
16036 KB |
Output is correct |
54 |
Correct |
56 ms |
15020 KB |
Output is correct |
55 |
Correct |
38 ms |
15276 KB |
Output is correct |
56 |
Correct |
1 ms |
2392 KB |
Output is correct |
57 |
Correct |
1 ms |
2392 KB |
Output is correct |
58 |
Correct |
1 ms |
2392 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
1 ms |
2652 KB |
Output is correct |
61 |
Correct |
67 ms |
15096 KB |
Output is correct |
62 |
Correct |
64 ms |
14004 KB |
Output is correct |
63 |
Correct |
48 ms |
9388 KB |
Output is correct |
64 |
Correct |
69 ms |
15268 KB |
Output is correct |
65 |
Correct |
60 ms |
18600 KB |
Output is correct |
66 |
Correct |
1 ms |
2392 KB |
Output is correct |
67 |
Correct |
1 ms |
2396 KB |
Output is correct |
68 |
Correct |
1 ms |
2396 KB |
Output is correct |
69 |
Correct |
1 ms |
2396 KB |
Output is correct |
70 |
Correct |
2 ms |
2648 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
1 ms |
2392 KB |
Output is correct |
73 |
Correct |
72 ms |
18004 KB |
Output is correct |
74 |
Correct |
66 ms |
17584 KB |
Output is correct |
75 |
Correct |
70 ms |
14492 KB |
Output is correct |
76 |
Correct |
72 ms |
16044 KB |
Output is correct |
77 |
Correct |
58 ms |
15792 KB |
Output is correct |
78 |
Correct |
28 ms |
8628 KB |
Output is correct |
79 |
Correct |
2 ms |
2652 KB |
Output is correct |
80 |
Correct |
2 ms |
2652 KB |
Output is correct |
81 |
Correct |
2 ms |
2784 KB |
Output is correct |
82 |
Correct |
3 ms |
2784 KB |
Output is correct |
83 |
Correct |
79 ms |
17576 KB |
Output is correct |
84 |
Correct |
76 ms |
16008 KB |
Output is correct |
85 |
Correct |
75 ms |
16728 KB |
Output is correct |
86 |
Correct |
80 ms |
18584 KB |
Output is correct |
87 |
Correct |
70 ms |
17828 KB |
Output is correct |
88 |
Correct |
73 ms |
18412 KB |
Output is correct |
89 |
Correct |
84 ms |
19748 KB |
Output is correct |
90 |
Correct |
76 ms |
18552 KB |
Output is correct |
91 |
Correct |
82 ms |
16804 KB |
Output is correct |
92 |
Correct |
76 ms |
16816 KB |
Output is correct |
93 |
Correct |
75 ms |
16552 KB |
Output is correct |
94 |
Correct |
78 ms |
15796 KB |
Output is correct |
95 |
Correct |
84 ms |
16548 KB |
Output is correct |
96 |
Correct |
73 ms |
17832 KB |
Output is correct |
97 |
Correct |
58 ms |
17572 KB |
Output is correct |
98 |
Correct |
44 ms |
19004 KB |
Output is correct |
99 |
Correct |
70 ms |
18852 KB |
Output is correct |