#include<bits/stdc++.h>
using namespace std;
const int maxn=150000+10;
int all[maxn][3],f,n,i,j,h,vis[maxn];
vector<int>a,b,c;
bool cmp(int a,int b){
return all[a][f]>all[b][f];
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>all[i][0]>>all[i][1]>>all[i][2];
a.push_back(i);
}
b=c=a;
sort(a.begin(),a.end(),cmp);
f=1;
sort(b.begin(),b.end(),cmp);
f=2;
sort(c.begin(),c.end(),cmp);
while(i<n&&j<n&&h<n){
if(vis[a[i]]==1)
i++;
else if(vis[b[j]]==1)
j++;
else if(vis[c[h]]==1)
h++;
else if(all[a[i]][1]==all[b[j]][1]||all[a[i]][2]==all[c[h]][2]){
vis[a[i]]=1;
i++;
}
else if(all[b[j]][0]==all[a[i]][0]||all[b[j]][2]==all[c[h]][2]){
vis[b[j]]=1;
j++;
}
else if(all[c[h]][0]==all[a[i]][0]||all[c[h]][1]==all[b[j]][1]){
vis[c[h]]=1;
h++;
}
else{
cout<<all[a[i]][0]+all[b[j]][1]+all[c[h]][2]<<"\n";
return 0;
}
}
cout<<-1<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2516 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2508 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2516 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2508 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2688 KB |
Output is correct |
29 |
Correct |
3 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2564 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2524 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
36 ms |
5308 KB |
Output is correct |
12 |
Correct |
31 ms |
4428 KB |
Output is correct |
13 |
Correct |
29 ms |
4824 KB |
Output is correct |
14 |
Correct |
40 ms |
5400 KB |
Output is correct |
15 |
Correct |
35 ms |
5592 KB |
Output is correct |
16 |
Correct |
31 ms |
5416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
36 ms |
5308 KB |
Output is correct |
12 |
Correct |
31 ms |
4428 KB |
Output is correct |
13 |
Correct |
29 ms |
4824 KB |
Output is correct |
14 |
Correct |
40 ms |
5400 KB |
Output is correct |
15 |
Correct |
35 ms |
5592 KB |
Output is correct |
16 |
Correct |
31 ms |
5416 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
46 ms |
5604 KB |
Output is correct |
23 |
Correct |
47 ms |
5460 KB |
Output is correct |
24 |
Correct |
33 ms |
4816 KB |
Output is correct |
25 |
Correct |
47 ms |
5580 KB |
Output is correct |
26 |
Correct |
35 ms |
5584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
36 ms |
5308 KB |
Output is correct |
12 |
Correct |
31 ms |
4428 KB |
Output is correct |
13 |
Correct |
29 ms |
4824 KB |
Output is correct |
14 |
Correct |
40 ms |
5400 KB |
Output is correct |
15 |
Correct |
35 ms |
5592 KB |
Output is correct |
16 |
Correct |
31 ms |
5416 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
46 ms |
5604 KB |
Output is correct |
23 |
Correct |
47 ms |
5460 KB |
Output is correct |
24 |
Correct |
33 ms |
4816 KB |
Output is correct |
25 |
Correct |
47 ms |
5580 KB |
Output is correct |
26 |
Correct |
35 ms |
5584 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2512 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2516 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
53 ms |
5864 KB |
Output is correct |
35 |
Correct |
53 ms |
5676 KB |
Output is correct |
36 |
Correct |
57 ms |
6172 KB |
Output is correct |
37 |
Correct |
62 ms |
6352 KB |
Output is correct |
38 |
Correct |
43 ms |
6096 KB |
Output is correct |
39 |
Correct |
23 ms |
4820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
36 ms |
5308 KB |
Output is correct |
12 |
Correct |
31 ms |
4428 KB |
Output is correct |
13 |
Correct |
29 ms |
4824 KB |
Output is correct |
14 |
Correct |
40 ms |
5400 KB |
Output is correct |
15 |
Correct |
35 ms |
5592 KB |
Output is correct |
16 |
Correct |
31 ms |
5416 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
46 ms |
5604 KB |
Output is correct |
23 |
Correct |
47 ms |
5460 KB |
Output is correct |
24 |
Correct |
33 ms |
4816 KB |
Output is correct |
25 |
Correct |
47 ms |
5580 KB |
Output is correct |
26 |
Correct |
35 ms |
5584 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2512 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2516 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
53 ms |
5864 KB |
Output is correct |
35 |
Correct |
53 ms |
5676 KB |
Output is correct |
36 |
Correct |
57 ms |
6172 KB |
Output is correct |
37 |
Correct |
62 ms |
6352 KB |
Output is correct |
38 |
Correct |
43 ms |
6096 KB |
Output is correct |
39 |
Correct |
23 ms |
4820 KB |
Output is correct |
40 |
Correct |
2 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
66 ms |
6464 KB |
Output is correct |
45 |
Correct |
69 ms |
6644 KB |
Output is correct |
46 |
Correct |
69 ms |
6580 KB |
Output is correct |
47 |
Correct |
70 ms |
6664 KB |
Output is correct |
48 |
Correct |
46 ms |
6792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2516 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2508 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2688 KB |
Output is correct |
29 |
Correct |
3 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2564 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2524 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2552 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
0 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
36 ms |
5308 KB |
Output is correct |
51 |
Correct |
31 ms |
4428 KB |
Output is correct |
52 |
Correct |
29 ms |
4824 KB |
Output is correct |
53 |
Correct |
40 ms |
5400 KB |
Output is correct |
54 |
Correct |
35 ms |
5592 KB |
Output is correct |
55 |
Correct |
31 ms |
5416 KB |
Output is correct |
56 |
Correct |
1 ms |
2392 KB |
Output is correct |
57 |
Correct |
1 ms |
2392 KB |
Output is correct |
58 |
Correct |
1 ms |
2392 KB |
Output is correct |
59 |
Correct |
1 ms |
2392 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
46 ms |
5604 KB |
Output is correct |
62 |
Correct |
47 ms |
5460 KB |
Output is correct |
63 |
Correct |
33 ms |
4816 KB |
Output is correct |
64 |
Correct |
47 ms |
5580 KB |
Output is correct |
65 |
Correct |
35 ms |
5584 KB |
Output is correct |
66 |
Correct |
1 ms |
2392 KB |
Output is correct |
67 |
Correct |
1 ms |
2512 KB |
Output is correct |
68 |
Correct |
1 ms |
2396 KB |
Output is correct |
69 |
Correct |
1 ms |
2516 KB |
Output is correct |
70 |
Correct |
2 ms |
2396 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
1 ms |
2396 KB |
Output is correct |
73 |
Correct |
53 ms |
5864 KB |
Output is correct |
74 |
Correct |
53 ms |
5676 KB |
Output is correct |
75 |
Correct |
57 ms |
6172 KB |
Output is correct |
76 |
Correct |
62 ms |
6352 KB |
Output is correct |
77 |
Correct |
43 ms |
6096 KB |
Output is correct |
78 |
Correct |
23 ms |
4820 KB |
Output is correct |
79 |
Correct |
2 ms |
2396 KB |
Output is correct |
80 |
Correct |
2 ms |
2396 KB |
Output is correct |
81 |
Correct |
1 ms |
2396 KB |
Output is correct |
82 |
Correct |
2 ms |
2652 KB |
Output is correct |
83 |
Correct |
66 ms |
6464 KB |
Output is correct |
84 |
Correct |
69 ms |
6644 KB |
Output is correct |
85 |
Correct |
69 ms |
6580 KB |
Output is correct |
86 |
Correct |
70 ms |
6664 KB |
Output is correct |
87 |
Correct |
46 ms |
6792 KB |
Output is correct |
88 |
Correct |
84 ms |
8400 KB |
Output is correct |
89 |
Correct |
94 ms |
8492 KB |
Output is correct |
90 |
Correct |
89 ms |
8444 KB |
Output is correct |
91 |
Correct |
89 ms |
8504 KB |
Output is correct |
92 |
Correct |
79 ms |
7120 KB |
Output is correct |
93 |
Correct |
86 ms |
7296 KB |
Output is correct |
94 |
Correct |
87 ms |
7056 KB |
Output is correct |
95 |
Correct |
56 ms |
8268 KB |
Output is correct |
96 |
Correct |
87 ms |
8396 KB |
Output is correct |
97 |
Correct |
45 ms |
8400 KB |
Output is correct |
98 |
Correct |
43 ms |
6872 KB |
Output is correct |
99 |
Correct |
49 ms |
7116 KB |
Output is correct |