#include <iostream>
#include <algorithm>
using namespace std;
struct Player {
long long a;
int ind;
bool friend operator < (Player x, Player y) {
return x.a<y.a;
}
};
const int MAXN=1e5+5e4+10;
long long x[MAXN], y[MAXN], z[MAXN];
int posx[MAXN], posy[MAXN], posz[MAXN];
bool used[MAXN];
bool cmpx (int i, int j) {
return x[i]<x[j];
}
bool cmpy (int i, int j) {
return y[i]<y[j];
}
bool cmpz (int i, int j) {
return z[i]<z[j];
}
int main () {
int n;
cin >> n;
for (int i=0;i<n;i++) {
cin >> x[i] >> y[i] >> z[i];
posx[i]=posy[i]=posz[i]=i;
}
sort(posx,posx+n,cmpx);
sort(posy,posy+n,cmpy);
sort(posz,posz+n,cmpz);
int ix, iy, iz;
ix=iy=iz=n-1;
while (ix>=0 && iy>=0 && iz>=0) {
//cout << posx[ix] << ' ' << posy[iy] << ' ' << posz[iz] << endl;
if (used[posx[ix]]) {
ix--;
continue;
}
if (used[posy[iy]]) {
iy--;
continue;
}
if (used[posz[iz]]) {
iz--;
continue;
}
if (y[posx[ix]]>=y[posy[iy]] || z[posx[ix]]>=z[posz[iz]]) {
used[posx[ix]]=true;
ix--;
continue;
}
if (x[posy[iy]]>=x[posx[ix]] || z[posy[iy]]>=z[posz[iz]]) {
used[posy[iy]]=true;
iy--;
continue;
}
if (x[posz[iz]]>=x[posx[ix]] || y[posz[iz]]>=y[posy[iy]]) {
used[posz[iz]]=true;
iz--;
continue;
}
cout << x[posx[ix]]+y[posy[iy]]+z[posz[iz]] << endl;
return 0;
}
cout << -1 << endl;
}
/*
5
3 1 4
2 3 1
1 5 5
4 4 2
5 2 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4488 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4548 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4488 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4548 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
5 ms |
4444 KB |
Output is correct |
27 |
Correct |
5 ms |
4444 KB |
Output is correct |
28 |
Correct |
5 ms |
4440 KB |
Output is correct |
29 |
Correct |
5 ms |
4672 KB |
Output is correct |
30 |
Correct |
3 ms |
4440 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
3 ms |
4440 KB |
Output is correct |
33 |
Correct |
4 ms |
4440 KB |
Output is correct |
34 |
Correct |
5 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
2 ms |
4444 KB |
Output is correct |
37 |
Correct |
3 ms |
4552 KB |
Output is correct |
38 |
Correct |
4 ms |
4444 KB |
Output is correct |
39 |
Correct |
2 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
63 ms |
5460 KB |
Output is correct |
12 |
Correct |
43 ms |
5212 KB |
Output is correct |
13 |
Correct |
50 ms |
6196 KB |
Output is correct |
14 |
Correct |
65 ms |
6580 KB |
Output is correct |
15 |
Correct |
61 ms |
6480 KB |
Output is correct |
16 |
Correct |
60 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
63 ms |
5460 KB |
Output is correct |
12 |
Correct |
43 ms |
5212 KB |
Output is correct |
13 |
Correct |
50 ms |
6196 KB |
Output is correct |
14 |
Correct |
65 ms |
6580 KB |
Output is correct |
15 |
Correct |
61 ms |
6480 KB |
Output is correct |
16 |
Correct |
60 ms |
6484 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
4540 KB |
Output is correct |
21 |
Correct |
2 ms |
4440 KB |
Output is correct |
22 |
Correct |
75 ms |
6624 KB |
Output is correct |
23 |
Correct |
69 ms |
6736 KB |
Output is correct |
24 |
Correct |
58 ms |
6164 KB |
Output is correct |
25 |
Correct |
89 ms |
6868 KB |
Output is correct |
26 |
Correct |
67 ms |
6704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
63 ms |
5460 KB |
Output is correct |
12 |
Correct |
43 ms |
5212 KB |
Output is correct |
13 |
Correct |
50 ms |
6196 KB |
Output is correct |
14 |
Correct |
65 ms |
6580 KB |
Output is correct |
15 |
Correct |
61 ms |
6480 KB |
Output is correct |
16 |
Correct |
60 ms |
6484 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
4540 KB |
Output is correct |
21 |
Correct |
2 ms |
4440 KB |
Output is correct |
22 |
Correct |
75 ms |
6624 KB |
Output is correct |
23 |
Correct |
69 ms |
6736 KB |
Output is correct |
24 |
Correct |
58 ms |
6164 KB |
Output is correct |
25 |
Correct |
89 ms |
6868 KB |
Output is correct |
26 |
Correct |
67 ms |
6704 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
88 ms |
7120 KB |
Output is correct |
35 |
Correct |
84 ms |
6956 KB |
Output is correct |
36 |
Correct |
92 ms |
7600 KB |
Output is correct |
37 |
Correct |
95 ms |
7504 KB |
Output is correct |
38 |
Correct |
79 ms |
7252 KB |
Output is correct |
39 |
Correct |
47 ms |
6224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4532 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
63 ms |
5460 KB |
Output is correct |
12 |
Correct |
43 ms |
5212 KB |
Output is correct |
13 |
Correct |
50 ms |
6196 KB |
Output is correct |
14 |
Correct |
65 ms |
6580 KB |
Output is correct |
15 |
Correct |
61 ms |
6480 KB |
Output is correct |
16 |
Correct |
60 ms |
6484 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
4540 KB |
Output is correct |
21 |
Correct |
2 ms |
4440 KB |
Output is correct |
22 |
Correct |
75 ms |
6624 KB |
Output is correct |
23 |
Correct |
69 ms |
6736 KB |
Output is correct |
24 |
Correct |
58 ms |
6164 KB |
Output is correct |
25 |
Correct |
89 ms |
6868 KB |
Output is correct |
26 |
Correct |
67 ms |
6704 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
88 ms |
7120 KB |
Output is correct |
35 |
Correct |
84 ms |
6956 KB |
Output is correct |
36 |
Correct |
92 ms |
7600 KB |
Output is correct |
37 |
Correct |
95 ms |
7504 KB |
Output is correct |
38 |
Correct |
79 ms |
7252 KB |
Output is correct |
39 |
Correct |
47 ms |
6224 KB |
Output is correct |
40 |
Correct |
3 ms |
4444 KB |
Output is correct |
41 |
Correct |
4 ms |
4440 KB |
Output is correct |
42 |
Correct |
3 ms |
4696 KB |
Output is correct |
43 |
Correct |
4 ms |
4440 KB |
Output is correct |
44 |
Correct |
114 ms |
7672 KB |
Output is correct |
45 |
Correct |
115 ms |
7756 KB |
Output is correct |
46 |
Correct |
126 ms |
7768 KB |
Output is correct |
47 |
Correct |
116 ms |
7764 KB |
Output is correct |
48 |
Correct |
92 ms |
7664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4488 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4548 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
5 ms |
4444 KB |
Output is correct |
27 |
Correct |
5 ms |
4444 KB |
Output is correct |
28 |
Correct |
5 ms |
4440 KB |
Output is correct |
29 |
Correct |
5 ms |
4672 KB |
Output is correct |
30 |
Correct |
3 ms |
4440 KB |
Output is correct |
31 |
Correct |
3 ms |
4444 KB |
Output is correct |
32 |
Correct |
3 ms |
4440 KB |
Output is correct |
33 |
Correct |
4 ms |
4440 KB |
Output is correct |
34 |
Correct |
5 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
2 ms |
4444 KB |
Output is correct |
37 |
Correct |
3 ms |
4552 KB |
Output is correct |
38 |
Correct |
4 ms |
4444 KB |
Output is correct |
39 |
Correct |
2 ms |
4552 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
1 ms |
4532 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
4440 KB |
Output is correct |
44 |
Correct |
1 ms |
4440 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
1 ms |
4440 KB |
Output is correct |
47 |
Correct |
1 ms |
4440 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
63 ms |
5460 KB |
Output is correct |
51 |
Correct |
43 ms |
5212 KB |
Output is correct |
52 |
Correct |
50 ms |
6196 KB |
Output is correct |
53 |
Correct |
65 ms |
6580 KB |
Output is correct |
54 |
Correct |
61 ms |
6480 KB |
Output is correct |
55 |
Correct |
60 ms |
6484 KB |
Output is correct |
56 |
Correct |
1 ms |
4444 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
58 |
Correct |
1 ms |
4440 KB |
Output is correct |
59 |
Correct |
1 ms |
4540 KB |
Output is correct |
60 |
Correct |
2 ms |
4440 KB |
Output is correct |
61 |
Correct |
75 ms |
6624 KB |
Output is correct |
62 |
Correct |
69 ms |
6736 KB |
Output is correct |
63 |
Correct |
58 ms |
6164 KB |
Output is correct |
64 |
Correct |
89 ms |
6868 KB |
Output is correct |
65 |
Correct |
67 ms |
6704 KB |
Output is correct |
66 |
Correct |
1 ms |
4444 KB |
Output is correct |
67 |
Correct |
1 ms |
4444 KB |
Output is correct |
68 |
Correct |
1 ms |
4444 KB |
Output is correct |
69 |
Correct |
1 ms |
4444 KB |
Output is correct |
70 |
Correct |
3 ms |
4444 KB |
Output is correct |
71 |
Correct |
1 ms |
4444 KB |
Output is correct |
72 |
Correct |
1 ms |
4444 KB |
Output is correct |
73 |
Correct |
88 ms |
7120 KB |
Output is correct |
74 |
Correct |
84 ms |
6956 KB |
Output is correct |
75 |
Correct |
92 ms |
7600 KB |
Output is correct |
76 |
Correct |
95 ms |
7504 KB |
Output is correct |
77 |
Correct |
79 ms |
7252 KB |
Output is correct |
78 |
Correct |
47 ms |
6224 KB |
Output is correct |
79 |
Correct |
3 ms |
4444 KB |
Output is correct |
80 |
Correct |
4 ms |
4440 KB |
Output is correct |
81 |
Correct |
3 ms |
4696 KB |
Output is correct |
82 |
Correct |
4 ms |
4440 KB |
Output is correct |
83 |
Correct |
114 ms |
7672 KB |
Output is correct |
84 |
Correct |
115 ms |
7756 KB |
Output is correct |
85 |
Correct |
126 ms |
7768 KB |
Output is correct |
86 |
Correct |
116 ms |
7764 KB |
Output is correct |
87 |
Correct |
92 ms |
7664 KB |
Output is correct |
88 |
Correct |
160 ms |
9604 KB |
Output is correct |
89 |
Correct |
164 ms |
9556 KB |
Output is correct |
90 |
Correct |
163 ms |
9644 KB |
Output is correct |
91 |
Correct |
165 ms |
9560 KB |
Output is correct |
92 |
Correct |
131 ms |
8156 KB |
Output is correct |
93 |
Correct |
142 ms |
8612 KB |
Output is correct |
94 |
Correct |
136 ms |
8272 KB |
Output is correct |
95 |
Correct |
131 ms |
9552 KB |
Output is correct |
96 |
Correct |
168 ms |
9704 KB |
Output is correct |
97 |
Correct |
127 ms |
9804 KB |
Output is correct |
98 |
Correct |
99 ms |
8144 KB |
Output is correct |
99 |
Correct |
150 ms |
8528 KB |
Output is correct |