#include <bits/stdc++.h>
//#define int long long
#define pi pair <int, int>
#define ppi pair <pi, int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
int n, t, c, f, g, h, X[150005], Y[150005], Z[150005];
vector <pi> x, y, z;
bool removed[150005];
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
/*int randnums[200005];
void gen(){
for(int i = 0; i < 200005; i++){
randnums[i] = rng() / 200005 + 1;
//cout << randnums[i] << '\n';
}
}*/
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
memset(removed, 0, sizeof(removed));
cin >> n;
for(int i = 1; i <= n; i++){
cin >> f >> g >> h;
X[i] = f, Y[i] = g, Z[i] = h;
x.pb({f, i}), y.pb({g, i}), z.pb({h, i});
}
sort(all(x)), sort(all(y)), sort(all(z));
while(1){
while(!x.empty() and removed[x.back().se]) x.pop_back();
while(!y.empty() and removed[y.back().se]) y.pop_back();
while(!z.empty() and removed[z.back().se]) z.pop_back();
if(x.empty() or y.empty() or z.empty()){
cout << -1;
break;
}
int i = -1, j = -1, k = -1;
if(!x.empty()){
i = x.back().se;
//cout << x.back().fi << ' ' << i << ' ';
}
if(!y.empty()){
j = y.back().se;
//cout << y.back().fi << ' ' << j << ' ';
}
if(!z.empty()){
k = z.back().se;
//cout << z.back().fi << ' ' << k << ' ';
}
//cout << '\n';
if(i == j and j == k and i != -1) x.pop_back(), y.pop_back(), z.pop_back(), removed[i] = 1;
else if(i == j and i != -1) x.pop_back(), y.pop_back(), removed[i] = 1;
else if(i == k and i != -1) x.pop_back(), z.pop_back(), removed[i] = 1;
else if(j == k and j != -1) y.pop_back(), z.pop_back(), removed[j] = 1;
else{
bool b = 0;
if(Y[i] == y.back().fi or Z[i] == z.back().fi) b = 1, removed[i] = 1, x.pop_back();
if(X[j] == x.back().fi or Z[j] == z.back().fi) b = 1, removed[j] = 1, y.pop_back();
if(X[k] == x.back().fi or Y[k] == y.back().fi) b = 1, removed[k] = 1, z.pop_back();
if(b) continue;
cout << x.back().fi + y.back().fi + z.back().fi;
//cout << '\n' << i << ' ' << j << ' ' << k;
break;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
476 KB |
Output is correct |
4 |
Correct |
1 ms |
480 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
480 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
480 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
480 KB |
Output is correct |
24 |
Correct |
1 ms |
472 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
476 KB |
Output is correct |
4 |
Correct |
1 ms |
480 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
480 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
480 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
480 KB |
Output is correct |
24 |
Correct |
1 ms |
472 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
724 KB |
Output is correct |
27 |
Correct |
3 ms |
732 KB |
Output is correct |
28 |
Correct |
3 ms |
724 KB |
Output is correct |
29 |
Correct |
3 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
704 KB |
Output is correct |
33 |
Correct |
3 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
488 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
668 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
476 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
63 ms |
7148 KB |
Output is correct |
12 |
Correct |
43 ms |
4656 KB |
Output is correct |
13 |
Correct |
49 ms |
5576 KB |
Output is correct |
14 |
Correct |
67 ms |
7040 KB |
Output is correct |
15 |
Correct |
60 ms |
7092 KB |
Output is correct |
16 |
Correct |
38 ms |
7076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
476 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
63 ms |
7148 KB |
Output is correct |
12 |
Correct |
43 ms |
4656 KB |
Output is correct |
13 |
Correct |
49 ms |
5576 KB |
Output is correct |
14 |
Correct |
67 ms |
7040 KB |
Output is correct |
15 |
Correct |
60 ms |
7092 KB |
Output is correct |
16 |
Correct |
38 ms |
7076 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
72 ms |
7388 KB |
Output is correct |
23 |
Correct |
68 ms |
7168 KB |
Output is correct |
24 |
Correct |
53 ms |
5212 KB |
Output is correct |
25 |
Correct |
86 ms |
7420 KB |
Output is correct |
26 |
Correct |
61 ms |
7220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
476 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
63 ms |
7148 KB |
Output is correct |
12 |
Correct |
43 ms |
4656 KB |
Output is correct |
13 |
Correct |
49 ms |
5576 KB |
Output is correct |
14 |
Correct |
67 ms |
7040 KB |
Output is correct |
15 |
Correct |
60 ms |
7092 KB |
Output is correct |
16 |
Correct |
38 ms |
7076 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
72 ms |
7388 KB |
Output is correct |
23 |
Correct |
68 ms |
7168 KB |
Output is correct |
24 |
Correct |
53 ms |
5212 KB |
Output is correct |
25 |
Correct |
86 ms |
7420 KB |
Output is correct |
26 |
Correct |
61 ms |
7220 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
476 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
75 ms |
7748 KB |
Output is correct |
35 |
Correct |
71 ms |
7696 KB |
Output is correct |
36 |
Correct |
75 ms |
7760 KB |
Output is correct |
37 |
Correct |
77 ms |
7680 KB |
Output is correct |
38 |
Correct |
65 ms |
7732 KB |
Output is correct |
39 |
Correct |
31 ms |
4748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
476 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
63 ms |
7148 KB |
Output is correct |
12 |
Correct |
43 ms |
4656 KB |
Output is correct |
13 |
Correct |
49 ms |
5576 KB |
Output is correct |
14 |
Correct |
67 ms |
7040 KB |
Output is correct |
15 |
Correct |
60 ms |
7092 KB |
Output is correct |
16 |
Correct |
38 ms |
7076 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
72 ms |
7388 KB |
Output is correct |
23 |
Correct |
68 ms |
7168 KB |
Output is correct |
24 |
Correct |
53 ms |
5212 KB |
Output is correct |
25 |
Correct |
86 ms |
7420 KB |
Output is correct |
26 |
Correct |
61 ms |
7220 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
476 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
75 ms |
7748 KB |
Output is correct |
35 |
Correct |
71 ms |
7696 KB |
Output is correct |
36 |
Correct |
75 ms |
7760 KB |
Output is correct |
37 |
Correct |
77 ms |
7680 KB |
Output is correct |
38 |
Correct |
65 ms |
7732 KB |
Output is correct |
39 |
Correct |
31 ms |
4748 KB |
Output is correct |
40 |
Correct |
2 ms |
620 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
596 KB |
Output is correct |
43 |
Correct |
2 ms |
724 KB |
Output is correct |
44 |
Correct |
80 ms |
7772 KB |
Output is correct |
45 |
Correct |
85 ms |
7604 KB |
Output is correct |
46 |
Correct |
80 ms |
7704 KB |
Output is correct |
47 |
Correct |
83 ms |
7728 KB |
Output is correct |
48 |
Correct |
78 ms |
7828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
476 KB |
Output is correct |
4 |
Correct |
1 ms |
480 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
480 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
480 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
480 KB |
Output is correct |
24 |
Correct |
1 ms |
472 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
724 KB |
Output is correct |
27 |
Correct |
3 ms |
732 KB |
Output is correct |
28 |
Correct |
3 ms |
724 KB |
Output is correct |
29 |
Correct |
3 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
704 KB |
Output is correct |
33 |
Correct |
3 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
488 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
668 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
472 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
472 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
476 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
63 ms |
7148 KB |
Output is correct |
51 |
Correct |
43 ms |
4656 KB |
Output is correct |
52 |
Correct |
49 ms |
5576 KB |
Output is correct |
53 |
Correct |
67 ms |
7040 KB |
Output is correct |
54 |
Correct |
60 ms |
7092 KB |
Output is correct |
55 |
Correct |
38 ms |
7076 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
480 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
2 ms |
468 KB |
Output is correct |
61 |
Correct |
72 ms |
7388 KB |
Output is correct |
62 |
Correct |
68 ms |
7168 KB |
Output is correct |
63 |
Correct |
53 ms |
5212 KB |
Output is correct |
64 |
Correct |
86 ms |
7420 KB |
Output is correct |
65 |
Correct |
61 ms |
7220 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
1 ms |
468 KB |
Output is correct |
68 |
Correct |
1 ms |
476 KB |
Output is correct |
69 |
Correct |
1 ms |
468 KB |
Output is correct |
70 |
Correct |
3 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
468 KB |
Output is correct |
73 |
Correct |
75 ms |
7748 KB |
Output is correct |
74 |
Correct |
71 ms |
7696 KB |
Output is correct |
75 |
Correct |
75 ms |
7760 KB |
Output is correct |
76 |
Correct |
77 ms |
7680 KB |
Output is correct |
77 |
Correct |
65 ms |
7732 KB |
Output is correct |
78 |
Correct |
31 ms |
4748 KB |
Output is correct |
79 |
Correct |
2 ms |
620 KB |
Output is correct |
80 |
Correct |
2 ms |
596 KB |
Output is correct |
81 |
Correct |
2 ms |
596 KB |
Output is correct |
82 |
Correct |
2 ms |
724 KB |
Output is correct |
83 |
Correct |
80 ms |
7772 KB |
Output is correct |
84 |
Correct |
85 ms |
7604 KB |
Output is correct |
85 |
Correct |
80 ms |
7704 KB |
Output is correct |
86 |
Correct |
83 ms |
7728 KB |
Output is correct |
87 |
Correct |
78 ms |
7828 KB |
Output is correct |
88 |
Correct |
82 ms |
7668 KB |
Output is correct |
89 |
Correct |
88 ms |
7672 KB |
Output is correct |
90 |
Correct |
86 ms |
7492 KB |
Output is correct |
91 |
Correct |
92 ms |
7756 KB |
Output is correct |
92 |
Correct |
92 ms |
7548 KB |
Output is correct |
93 |
Correct |
81 ms |
7624 KB |
Output is correct |
94 |
Correct |
82 ms |
7472 KB |
Output is correct |
95 |
Correct |
89 ms |
7696 KB |
Output is correct |
96 |
Correct |
80 ms |
7476 KB |
Output is correct |
97 |
Correct |
60 ms |
7576 KB |
Output is correct |
98 |
Correct |
48 ms |
7724 KB |
Output is correct |
99 |
Correct |
86 ms |
7612 KB |
Output is correct |