#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
static int n,i,state,x_id,y_id,z_id;
static pair<int,int> x[150005],y[150005],z[150005],x_max,y_max,z_max;
static tuple<int,int,int> t[150005];
bool elm[150005];
cin>>n;
for (i=1;i<n+1;i++)
{
cin>>x[i].fi>>y[i].fi>>z[i].fi;
x[i].se=y[i].se=z[i].se=i;
t[i]={x[i].fi,y[i].fi,z[i].fi};
elm[i]=false;
}
sort(x+1,x+n+1);
sort(y+1,y+n+1);
sort(z+1,z+n+1);
x_id=y_id=z_id=n;
x_max=x[n];
y_max=y[n];
z_max=z[n];
do
{
// cout<<x_max.fi<<y_max.fi<<z_max.fi<<"\n";
state=0;
if (elm[x_max.se]
or get<1>(t[x_max.se])>=get<1>(t[y_max.se])
or get<2>(t[x_max.se])>=get<2>(t[z_max.se])) state=1;
if (elm[y_max.se]
or get<0>(t[y_max.se])>=get<0>(t[x_max.se])
or get<2>(t[y_max.se])>=get<2>(t[z_max.se])) state=2;
if (elm[z_max.se]
or get<0>(t[z_max.se])>=get<0>(t[x_max.se])
or get<1>(t[z_max.se])>=get<1>(t[y_max.se])) state=3;
if (state==1)
{
if (x_id==1)
{
cout<<-1;return 0;
}
elm[x_max.se]=true;
x_id--;x_max=x[x_id];
}
if (state==2)
{
if (y_id==1)
{
cout<<-1;return 0;
}
elm[y_max.se]=true;
y_id--;y_max=y[y_id];
}
if (state==3)
{
if (z_id==1)
{
cout<<-1;return 0;
}
elm[z_max.se]=true;
z_id--;z_max=z[z_id];
}
}
while (state!=0);
if (state==-1) cout<<-1;
else cout<<x_max.fi + y_max.fi + z_max.fi;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
472 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 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 |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
472 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 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 |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
472 KB |
Output is correct |
26 |
Correct |
2 ms |
864 KB |
Output is correct |
27 |
Correct |
3 ms |
868 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
712 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
2 ms |
852 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
724 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
472 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 |
60 ms |
11892 KB |
Output is correct |
12 |
Correct |
44 ms |
8012 KB |
Output is correct |
13 |
Correct |
44 ms |
9884 KB |
Output is correct |
14 |
Correct |
64 ms |
11896 KB |
Output is correct |
15 |
Correct |
56 ms |
11860 KB |
Output is correct |
16 |
Correct |
32 ms |
11852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
472 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 |
60 ms |
11892 KB |
Output is correct |
12 |
Correct |
44 ms |
8012 KB |
Output is correct |
13 |
Correct |
44 ms |
9884 KB |
Output is correct |
14 |
Correct |
64 ms |
11896 KB |
Output is correct |
15 |
Correct |
56 ms |
11860 KB |
Output is correct |
16 |
Correct |
32 ms |
11852 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 |
596 KB |
Output is correct |
22 |
Correct |
83 ms |
12140 KB |
Output is correct |
23 |
Correct |
68 ms |
11724 KB |
Output is correct |
24 |
Correct |
51 ms |
8916 KB |
Output is correct |
25 |
Correct |
74 ms |
12136 KB |
Output is correct |
26 |
Correct |
57 ms |
12016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
472 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 |
60 ms |
11892 KB |
Output is correct |
12 |
Correct |
44 ms |
8012 KB |
Output is correct |
13 |
Correct |
44 ms |
9884 KB |
Output is correct |
14 |
Correct |
64 ms |
11896 KB |
Output is correct |
15 |
Correct |
56 ms |
11860 KB |
Output is correct |
16 |
Correct |
32 ms |
11852 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 |
596 KB |
Output is correct |
22 |
Correct |
83 ms |
12140 KB |
Output is correct |
23 |
Correct |
68 ms |
11724 KB |
Output is correct |
24 |
Correct |
51 ms |
8916 KB |
Output is correct |
25 |
Correct |
74 ms |
12136 KB |
Output is correct |
26 |
Correct |
57 ms |
12016 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 |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
71 ms |
12188 KB |
Output is correct |
35 |
Correct |
70 ms |
11452 KB |
Output is correct |
36 |
Correct |
74 ms |
12544 KB |
Output is correct |
37 |
Correct |
75 ms |
12596 KB |
Output is correct |
38 |
Correct |
59 ms |
12276 KB |
Output is correct |
39 |
Correct |
30 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
472 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 |
60 ms |
11892 KB |
Output is correct |
12 |
Correct |
44 ms |
8012 KB |
Output is correct |
13 |
Correct |
44 ms |
9884 KB |
Output is correct |
14 |
Correct |
64 ms |
11896 KB |
Output is correct |
15 |
Correct |
56 ms |
11860 KB |
Output is correct |
16 |
Correct |
32 ms |
11852 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 |
596 KB |
Output is correct |
22 |
Correct |
83 ms |
12140 KB |
Output is correct |
23 |
Correct |
68 ms |
11724 KB |
Output is correct |
24 |
Correct |
51 ms |
8916 KB |
Output is correct |
25 |
Correct |
74 ms |
12136 KB |
Output is correct |
26 |
Correct |
57 ms |
12016 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 |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
71 ms |
12188 KB |
Output is correct |
35 |
Correct |
70 ms |
11452 KB |
Output is correct |
36 |
Correct |
74 ms |
12544 KB |
Output is correct |
37 |
Correct |
75 ms |
12596 KB |
Output is correct |
38 |
Correct |
59 ms |
12276 KB |
Output is correct |
39 |
Correct |
30 ms |
7800 KB |
Output is correct |
40 |
Correct |
2 ms |
612 KB |
Output is correct |
41 |
Correct |
2 ms |
724 KB |
Output is correct |
42 |
Correct |
2 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
724 KB |
Output is correct |
44 |
Correct |
73 ms |
13088 KB |
Output is correct |
45 |
Correct |
80 ms |
13140 KB |
Output is correct |
46 |
Correct |
78 ms |
13028 KB |
Output is correct |
47 |
Correct |
79 ms |
13092 KB |
Output is correct |
48 |
Correct |
68 ms |
12976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
472 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 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 |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
472 KB |
Output is correct |
26 |
Correct |
2 ms |
864 KB |
Output is correct |
27 |
Correct |
3 ms |
868 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
712 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
2 ms |
852 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
724 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
596 KB |
Output is correct |
40 |
Correct |
1 ms |
464 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
472 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 |
60 ms |
11892 KB |
Output is correct |
51 |
Correct |
44 ms |
8012 KB |
Output is correct |
52 |
Correct |
44 ms |
9884 KB |
Output is correct |
53 |
Correct |
64 ms |
11896 KB |
Output is correct |
54 |
Correct |
56 ms |
11860 KB |
Output is correct |
55 |
Correct |
32 ms |
11852 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 |
468 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
596 KB |
Output is correct |
61 |
Correct |
83 ms |
12140 KB |
Output is correct |
62 |
Correct |
68 ms |
11724 KB |
Output is correct |
63 |
Correct |
51 ms |
8916 KB |
Output is correct |
64 |
Correct |
74 ms |
12136 KB |
Output is correct |
65 |
Correct |
57 ms |
12016 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 |
468 KB |
Output is correct |
69 |
Correct |
1 ms |
468 KB |
Output is correct |
70 |
Correct |
2 ms |
724 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
468 KB |
Output is correct |
73 |
Correct |
71 ms |
12188 KB |
Output is correct |
74 |
Correct |
70 ms |
11452 KB |
Output is correct |
75 |
Correct |
74 ms |
12544 KB |
Output is correct |
76 |
Correct |
75 ms |
12596 KB |
Output is correct |
77 |
Correct |
59 ms |
12276 KB |
Output is correct |
78 |
Correct |
30 ms |
7800 KB |
Output is correct |
79 |
Correct |
2 ms |
612 KB |
Output is correct |
80 |
Correct |
2 ms |
724 KB |
Output is correct |
81 |
Correct |
2 ms |
724 KB |
Output is correct |
82 |
Correct |
2 ms |
724 KB |
Output is correct |
83 |
Correct |
73 ms |
13088 KB |
Output is correct |
84 |
Correct |
80 ms |
13140 KB |
Output is correct |
85 |
Correct |
78 ms |
13028 KB |
Output is correct |
86 |
Correct |
79 ms |
13092 KB |
Output is correct |
87 |
Correct |
68 ms |
12976 KB |
Output is correct |
88 |
Correct |
75 ms |
13612 KB |
Output is correct |
89 |
Correct |
86 ms |
13704 KB |
Output is correct |
90 |
Correct |
81 ms |
13580 KB |
Output is correct |
91 |
Correct |
92 ms |
13636 KB |
Output is correct |
92 |
Correct |
79 ms |
13344 KB |
Output is correct |
93 |
Correct |
79 ms |
13656 KB |
Output is correct |
94 |
Correct |
80 ms |
13628 KB |
Output is correct |
95 |
Correct |
82 ms |
13772 KB |
Output is correct |
96 |
Correct |
77 ms |
13644 KB |
Output is correct |
97 |
Correct |
51 ms |
13624 KB |
Output is correct |
98 |
Correct |
43 ms |
13552 KB |
Output is correct |
99 |
Correct |
71 ms |
13540 KB |
Output is correct |