#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi pair <int, int>
pair <pi, int> p[150005];
bool cmp1(int x, int y){
return p[x].fi.fi > p[y].fi.fi;
}
bool cmp2(int x, int y){
return p[x].fi.se > p[y].fi.se;
}
bool cmp3(int x, int y){
return p[x].se > p[y].se;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, ptr1 = 0, ptr2 = 0, ptr3 = 0, xp, yp, zp, markcnt = 0; cin >> n;
bool marked[n];
fill(marked, marked + n, 0);
for (int i = 0; i < n; i++){
cin >> p[i].fi.fi >> p[i].fi.se >> p[i].se;
}
int a[n], b[n], c[n];
for (int i = 0; i < n; i++) a[i] = b[i] = c[i] = i;
sort(a, a + n, cmp1);
sort(b, b + n, cmp2);
sort(c, c + n, cmp3);
while (ptr1 != n and ptr2 != n and ptr3 != n){
while (marked[a[ptr1]]) ptr1++;
while (marked[b[ptr2]]) ptr2++;
while (marked[c[ptr3]]) ptr3++;
xp = a[ptr1]; yp = b[ptr2]; zp = c[ptr3];
//cerr << xp << ' ' << yp << ' ' << zp << '\n';
if (p[xp].fi.fi <= max(p[yp].fi.fi, p[zp].fi.fi)){
if (p[xp].fi.fi <= p[yp].fi.fi) marked[yp] = true;
else marked[zp] = true;
markcnt += 1;
if (markcnt == n){
cout << -1;
return 0;
}
continue;
}
if (p[yp].fi.se <= max(p[xp].fi.se, p[zp].fi.se)){
if (p[yp].fi.se <= p[xp].fi.se) marked[xp] = true;
else marked[zp] = true;
markcnt += 1;
if (markcnt == n){
cout << -1;
return 0;
}
continue;
}
if (p[zp].se <= max(p[xp].se, p[yp].se)){
if (p[zp].se <= p[xp].se) marked[xp] = true;
else marked[yp] = true;
markcnt += 1;
if (markcnt == n){
cout << -1;
return 0;
}
continue;
}
cout << p[xp].fi.fi + p[yp].fi.se + p[zp].se;
return 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
404 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
476 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
388 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
42 ms |
4484 KB |
Output is correct |
12 |
Correct |
30 ms |
3200 KB |
Output is correct |
13 |
Correct |
33 ms |
3804 KB |
Output is correct |
14 |
Correct |
46 ms |
4380 KB |
Output is correct |
15 |
Correct |
39 ms |
4392 KB |
Output is correct |
16 |
Correct |
40 ms |
4484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
42 ms |
4484 KB |
Output is correct |
12 |
Correct |
30 ms |
3200 KB |
Output is correct |
13 |
Correct |
33 ms |
3804 KB |
Output is correct |
14 |
Correct |
46 ms |
4380 KB |
Output is correct |
15 |
Correct |
39 ms |
4392 KB |
Output is correct |
16 |
Correct |
40 ms |
4484 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
54 ms |
5096 KB |
Output is correct |
23 |
Correct |
46 ms |
4808 KB |
Output is correct |
24 |
Correct |
39 ms |
3748 KB |
Output is correct |
25 |
Correct |
54 ms |
5104 KB |
Output is correct |
26 |
Correct |
41 ms |
4968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
42 ms |
4484 KB |
Output is correct |
12 |
Correct |
30 ms |
3200 KB |
Output is correct |
13 |
Correct |
33 ms |
3804 KB |
Output is correct |
14 |
Correct |
46 ms |
4380 KB |
Output is correct |
15 |
Correct |
39 ms |
4392 KB |
Output is correct |
16 |
Correct |
40 ms |
4484 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
54 ms |
5096 KB |
Output is correct |
23 |
Correct |
46 ms |
4808 KB |
Output is correct |
24 |
Correct |
39 ms |
3748 KB |
Output is correct |
25 |
Correct |
54 ms |
5104 KB |
Output is correct |
26 |
Correct |
41 ms |
4968 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
60 ms |
5216 KB |
Output is correct |
35 |
Correct |
58 ms |
4940 KB |
Output is correct |
36 |
Correct |
63 ms |
5496 KB |
Output is correct |
37 |
Correct |
65 ms |
5456 KB |
Output is correct |
38 |
Correct |
47 ms |
5340 KB |
Output is correct |
39 |
Correct |
29 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
42 ms |
4484 KB |
Output is correct |
12 |
Correct |
30 ms |
3200 KB |
Output is correct |
13 |
Correct |
33 ms |
3804 KB |
Output is correct |
14 |
Correct |
46 ms |
4380 KB |
Output is correct |
15 |
Correct |
39 ms |
4392 KB |
Output is correct |
16 |
Correct |
40 ms |
4484 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
54 ms |
5096 KB |
Output is correct |
23 |
Correct |
46 ms |
4808 KB |
Output is correct |
24 |
Correct |
39 ms |
3748 KB |
Output is correct |
25 |
Correct |
54 ms |
5104 KB |
Output is correct |
26 |
Correct |
41 ms |
4968 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
60 ms |
5216 KB |
Output is correct |
35 |
Correct |
58 ms |
4940 KB |
Output is correct |
36 |
Correct |
63 ms |
5496 KB |
Output is correct |
37 |
Correct |
65 ms |
5456 KB |
Output is correct |
38 |
Correct |
47 ms |
5340 KB |
Output is correct |
39 |
Correct |
29 ms |
3412 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
392 KB |
Output is correct |
44 |
Correct |
79 ms |
5500 KB |
Output is correct |
45 |
Correct |
82 ms |
5580 KB |
Output is correct |
46 |
Correct |
82 ms |
5396 KB |
Output is correct |
47 |
Correct |
80 ms |
5504 KB |
Output is correct |
48 |
Correct |
55 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
404 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
476 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
388 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
42 ms |
4484 KB |
Output is correct |
51 |
Correct |
30 ms |
3200 KB |
Output is correct |
52 |
Correct |
33 ms |
3804 KB |
Output is correct |
53 |
Correct |
46 ms |
4380 KB |
Output is correct |
54 |
Correct |
39 ms |
4392 KB |
Output is correct |
55 |
Correct |
40 ms |
4484 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
336 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
54 ms |
5096 KB |
Output is correct |
62 |
Correct |
46 ms |
4808 KB |
Output is correct |
63 |
Correct |
39 ms |
3748 KB |
Output is correct |
64 |
Correct |
54 ms |
5104 KB |
Output is correct |
65 |
Correct |
41 ms |
4968 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
212 KB |
Output is correct |
70 |
Correct |
3 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
60 ms |
5216 KB |
Output is correct |
74 |
Correct |
58 ms |
4940 KB |
Output is correct |
75 |
Correct |
63 ms |
5496 KB |
Output is correct |
76 |
Correct |
65 ms |
5456 KB |
Output is correct |
77 |
Correct |
47 ms |
5340 KB |
Output is correct |
78 |
Correct |
29 ms |
3412 KB |
Output is correct |
79 |
Correct |
2 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
468 KB |
Output is correct |
81 |
Correct |
2 ms |
468 KB |
Output is correct |
82 |
Correct |
2 ms |
392 KB |
Output is correct |
83 |
Correct |
79 ms |
5500 KB |
Output is correct |
84 |
Correct |
82 ms |
5580 KB |
Output is correct |
85 |
Correct |
82 ms |
5396 KB |
Output is correct |
86 |
Correct |
80 ms |
5504 KB |
Output is correct |
87 |
Correct |
55 ms |
5452 KB |
Output is correct |
88 |
Correct |
97 ms |
5468 KB |
Output is correct |
89 |
Correct |
112 ms |
5544 KB |
Output is correct |
90 |
Correct |
102 ms |
5452 KB |
Output is correct |
91 |
Correct |
107 ms |
5568 KB |
Output is correct |
92 |
Correct |
101 ms |
5452 KB |
Output is correct |
93 |
Correct |
98 ms |
5452 KB |
Output is correct |
94 |
Correct |
98 ms |
5508 KB |
Output is correct |
95 |
Correct |
74 ms |
5620 KB |
Output is correct |
96 |
Correct |
98 ms |
5400 KB |
Output is correct |
97 |
Correct |
55 ms |
5452 KB |
Output is correct |
98 |
Correct |
50 ms |
5504 KB |
Output is correct |
99 |
Correct |
55 ms |
5404 KB |
Output is correct |