#include <algorithm>
#include <iostream>
#include <climits>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using ull = unsigned long long;
using ll = long long;
//#define int __int128
//#define int ll
#define pii pair <int, int>
#define all(a) (a).begin(), (a).end()
#define fr first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define vt vector
#define FOR(a, b) for(int i = (a); i <= (b); i++)
#define FORr(a, b) for(int i = (a); i >= (b); i--)
#define sz(x) (int)(x).size()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rangerng(int l, int r){
return uniform_int_distribution<>(l, r)(rng);
}
////////////////////////////////////////////////////////////////////////////////////
const int NMAX = 150000;
struct obj{
int x, y, z;
}v[NMAX + 1];
map <pii, set <int>> llo, lol, oll;
multiset <int> fx, fy, fz;
void del(int ind){
fx.erase(fx.find(v[ind].x));
fy.erase(fy.find(v[ind].y));
fz.erase(fz.find(v[ind].z));
llo[{v[ind].x, v[ind].y}].erase(ind);
lol[{v[ind].x, v[ind].z}].erase(ind);
oll[{v[ind].y, v[ind].z}].erase(ind);
}
void solve(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> v[i].x >> v[i].y >> v[i].z;
llo[{v[i].x, v[i].y}].insert(i);
lol[{v[i].x, v[i].z}].insert(i);
oll[{v[i].y, v[i].z}].insert(i);
fx.insert(v[i].x);
fy.insert(v[i].y);
fz.insert(v[i].z);
}
while(true){
bool found = 0;
int maxX, maxY, maxZ;
if(fx.empty() || fy.empty() || fz.empty()){
break;
}
maxX = (*fx.rbegin());
maxY = (*fy.rbegin());
vector <int> inds;
for(int ind : llo[{maxX, maxY}]){
inds.pb(ind);
found = 1;
}
for(int x : inds){
del(x);
}
inds.clear();
if(fx.empty() || fy.empty() || fz.empty()){
break;
}
maxX = (*fx.rbegin());
maxZ = (*fz.rbegin());
for(int ind : lol[{maxX, maxZ}]){
found = 1;
inds.pb(ind);
}
for(int x : inds){
del(x);
}
inds.clear();
if(fx.empty() || fy.empty() || fz.empty()){
break;
}
maxY = (*fy.rbegin());
maxZ = (*fz.rbegin());
for(int ind : oll[{maxY, maxZ}]){
found = 1;
inds.pb(ind);
}
for(int x : inds){
del(x);
}
inds.clear();
if(!found){
break;
}
}
if(sz(fx) < 3){
cout << -1 << '\n';
return;
}
int sum = (*fx.rbegin()) + (*fy.rbegin()) + (*fz.rbegin());
cout << sum << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int T;
//cin >> T;
T = 1;
while(T--){
solve();
}
return 0;
}
/*
3
1 2 2
2 1 2
2 2 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
472 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
472 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
8 ms |
2652 KB |
Output is correct |
27 |
Correct |
9 ms |
2860 KB |
Output is correct |
28 |
Correct |
8 ms |
2656 KB |
Output is correct |
29 |
Correct |
9 ms |
2656 KB |
Output is correct |
30 |
Correct |
6 ms |
1888 KB |
Output is correct |
31 |
Correct |
6 ms |
2604 KB |
Output is correct |
32 |
Correct |
8 ms |
2652 KB |
Output is correct |
33 |
Correct |
7 ms |
2268 KB |
Output is correct |
34 |
Correct |
7 ms |
2656 KB |
Output is correct |
35 |
Correct |
1 ms |
876 KB |
Output is correct |
36 |
Correct |
1 ms |
864 KB |
Output is correct |
37 |
Correct |
4 ms |
2400 KB |
Output is correct |
38 |
Correct |
7 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
1120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
0 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
339 ms |
45200 KB |
Output is correct |
12 |
Correct |
241 ms |
30464 KB |
Output is correct |
13 |
Correct |
193 ms |
37432 KB |
Output is correct |
14 |
Correct |
421 ms |
45412 KB |
Output is correct |
15 |
Correct |
291 ms |
45856 KB |
Output is correct |
16 |
Correct |
216 ms |
46428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
0 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
339 ms |
45200 KB |
Output is correct |
12 |
Correct |
241 ms |
30464 KB |
Output is correct |
13 |
Correct |
193 ms |
37432 KB |
Output is correct |
14 |
Correct |
421 ms |
45412 KB |
Output is correct |
15 |
Correct |
291 ms |
45856 KB |
Output is correct |
16 |
Correct |
216 ms |
46428 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
472 ms |
45736 KB |
Output is correct |
23 |
Correct |
447 ms |
44460 KB |
Output is correct |
24 |
Correct |
372 ms |
33056 KB |
Output is correct |
25 |
Correct |
583 ms |
45552 KB |
Output is correct |
26 |
Correct |
298 ms |
46076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
0 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
339 ms |
45200 KB |
Output is correct |
12 |
Correct |
241 ms |
30464 KB |
Output is correct |
13 |
Correct |
193 ms |
37432 KB |
Output is correct |
14 |
Correct |
421 ms |
45412 KB |
Output is correct |
15 |
Correct |
291 ms |
45856 KB |
Output is correct |
16 |
Correct |
216 ms |
46428 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
472 ms |
45736 KB |
Output is correct |
23 |
Correct |
447 ms |
44460 KB |
Output is correct |
24 |
Correct |
372 ms |
33056 KB |
Output is correct |
25 |
Correct |
583 ms |
45552 KB |
Output is correct |
26 |
Correct |
298 ms |
46076 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
9 ms |
2288 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
707 ms |
63992 KB |
Output is correct |
35 |
Correct |
714 ms |
56660 KB |
Output is correct |
36 |
Correct |
868 ms |
59116 KB |
Output is correct |
37 |
Correct |
918 ms |
58088 KB |
Output is correct |
38 |
Correct |
387 ms |
45528 KB |
Output is correct |
39 |
Correct |
217 ms |
36436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
0 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
339 ms |
45200 KB |
Output is correct |
12 |
Correct |
241 ms |
30464 KB |
Output is correct |
13 |
Correct |
193 ms |
37432 KB |
Output is correct |
14 |
Correct |
421 ms |
45412 KB |
Output is correct |
15 |
Correct |
291 ms |
45856 KB |
Output is correct |
16 |
Correct |
216 ms |
46428 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
472 ms |
45736 KB |
Output is correct |
23 |
Correct |
447 ms |
44460 KB |
Output is correct |
24 |
Correct |
372 ms |
33056 KB |
Output is correct |
25 |
Correct |
583 ms |
45552 KB |
Output is correct |
26 |
Correct |
298 ms |
46076 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
9 ms |
2288 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
707 ms |
63992 KB |
Output is correct |
35 |
Correct |
714 ms |
56660 KB |
Output is correct |
36 |
Correct |
868 ms |
59116 KB |
Output is correct |
37 |
Correct |
918 ms |
58088 KB |
Output is correct |
38 |
Correct |
387 ms |
45528 KB |
Output is correct |
39 |
Correct |
217 ms |
36436 KB |
Output is correct |
40 |
Correct |
5 ms |
1884 KB |
Output is correct |
41 |
Correct |
6 ms |
2904 KB |
Output is correct |
42 |
Correct |
4 ms |
2272 KB |
Output is correct |
43 |
Correct |
6 ms |
2396 KB |
Output is correct |
44 |
Correct |
884 ms |
88524 KB |
Output is correct |
45 |
Correct |
1052 ms |
76744 KB |
Output is correct |
46 |
Correct |
1041 ms |
80672 KB |
Output is correct |
47 |
Correct |
1095 ms |
75760 KB |
Output is correct |
48 |
Correct |
472 ms |
48100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
472 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
8 ms |
2652 KB |
Output is correct |
27 |
Correct |
9 ms |
2860 KB |
Output is correct |
28 |
Correct |
8 ms |
2656 KB |
Output is correct |
29 |
Correct |
9 ms |
2656 KB |
Output is correct |
30 |
Correct |
6 ms |
1888 KB |
Output is correct |
31 |
Correct |
6 ms |
2604 KB |
Output is correct |
32 |
Correct |
8 ms |
2652 KB |
Output is correct |
33 |
Correct |
7 ms |
2268 KB |
Output is correct |
34 |
Correct |
7 ms |
2656 KB |
Output is correct |
35 |
Correct |
1 ms |
876 KB |
Output is correct |
36 |
Correct |
1 ms |
864 KB |
Output is correct |
37 |
Correct |
4 ms |
2400 KB |
Output is correct |
38 |
Correct |
7 ms |
2396 KB |
Output is correct |
39 |
Correct |
2 ms |
1120 KB |
Output is correct |
40 |
Correct |
0 ms |
352 KB |
Output is correct |
41 |
Correct |
0 ms |
352 KB |
Output is correct |
42 |
Correct |
0 ms |
352 KB |
Output is correct |
43 |
Correct |
0 ms |
352 KB |
Output is correct |
44 |
Correct |
1 ms |
352 KB |
Output is correct |
45 |
Correct |
1 ms |
356 KB |
Output is correct |
46 |
Correct |
1 ms |
608 KB |
Output is correct |
47 |
Correct |
0 ms |
352 KB |
Output is correct |
48 |
Correct |
0 ms |
352 KB |
Output is correct |
49 |
Correct |
0 ms |
352 KB |
Output is correct |
50 |
Correct |
339 ms |
45200 KB |
Output is correct |
51 |
Correct |
241 ms |
30464 KB |
Output is correct |
52 |
Correct |
193 ms |
37432 KB |
Output is correct |
53 |
Correct |
421 ms |
45412 KB |
Output is correct |
54 |
Correct |
291 ms |
45856 KB |
Output is correct |
55 |
Correct |
216 ms |
46428 KB |
Output is correct |
56 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
2 ms |
1116 KB |
Output is correct |
61 |
Correct |
472 ms |
45736 KB |
Output is correct |
62 |
Correct |
447 ms |
44460 KB |
Output is correct |
63 |
Correct |
372 ms |
33056 KB |
Output is correct |
64 |
Correct |
583 ms |
45552 KB |
Output is correct |
65 |
Correct |
298 ms |
46076 KB |
Output is correct |
66 |
Correct |
1 ms |
600 KB |
Output is correct |
67 |
Correct |
1 ms |
472 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
1 ms |
604 KB |
Output is correct |
70 |
Correct |
9 ms |
2288 KB |
Output is correct |
71 |
Correct |
2 ms |
860 KB |
Output is correct |
72 |
Correct |
2 ms |
856 KB |
Output is correct |
73 |
Correct |
707 ms |
63992 KB |
Output is correct |
74 |
Correct |
714 ms |
56660 KB |
Output is correct |
75 |
Correct |
868 ms |
59116 KB |
Output is correct |
76 |
Correct |
918 ms |
58088 KB |
Output is correct |
77 |
Correct |
387 ms |
45528 KB |
Output is correct |
78 |
Correct |
217 ms |
36436 KB |
Output is correct |
79 |
Correct |
5 ms |
1884 KB |
Output is correct |
80 |
Correct |
6 ms |
2904 KB |
Output is correct |
81 |
Correct |
4 ms |
2272 KB |
Output is correct |
82 |
Correct |
6 ms |
2396 KB |
Output is correct |
83 |
Correct |
884 ms |
88524 KB |
Output is correct |
84 |
Correct |
1052 ms |
76744 KB |
Output is correct |
85 |
Correct |
1041 ms |
80672 KB |
Output is correct |
86 |
Correct |
1095 ms |
75760 KB |
Output is correct |
87 |
Correct |
472 ms |
48100 KB |
Output is correct |
88 |
Correct |
665 ms |
90572 KB |
Output is correct |
89 |
Correct |
870 ms |
88976 KB |
Output is correct |
90 |
Correct |
761 ms |
90568 KB |
Output is correct |
91 |
Correct |
937 ms |
87640 KB |
Output is correct |
92 |
Correct |
857 ms |
87900 KB |
Output is correct |
93 |
Correct |
960 ms |
87888 KB |
Output is correct |
94 |
Correct |
1036 ms |
84924 KB |
Output is correct |
95 |
Correct |
603 ms |
69840 KB |
Output is correct |
96 |
Correct |
527 ms |
91008 KB |
Output is correct |
97 |
Correct |
230 ms |
49584 KB |
Output is correct |
98 |
Correct |
279 ms |
75192 KB |
Output is correct |
99 |
Correct |
317 ms |
75344 KB |
Output is correct |