#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n,a[150001],b[150001],c[150001];
multiset<int, greater<int>> ms[3];
map<pii,vector<int>> mp[3];
bool del[150001];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
for (int i=0; i<n; ++i) {
cin>>a[i]>>b[i]>>c[i];
ms[0].insert(a[i]);
ms[1].insert(b[i]);
ms[2].insert(c[i]);
mp[0][pii(a[i],b[i])].push_back(i);
mp[1][pii(b[i],c[i])].push_back(i);
mp[2][pii(c[i],a[i])].push_back(i);
}
while (true) {
int A=*(ms[0].begin()), B=*(ms[1].begin()), C=*(ms[2].begin());
vector<int> temp;
for (auto s : mp[0][pii(A,B)]) if (!del[s]) temp.push_back(s);
for (auto s : mp[1][pii(B,C)]) if (!del[s]) temp.push_back(s);
for (auto s : mp[2][pii(C,A)]) if (!del[s]) temp.push_back(s);
if (temp.size()==0) {
cout<<A+B+C;
return 0;
}
for (auto s : temp) {
if (del[s]) continue;
del[s]=true;
ms[0].erase(ms[0].find(a[s]));
ms[1].erase(ms[1].find(b[s]));
ms[2].erase(ms[2].find(c[s]));
}
if (ms[0].size()==0 || ms[1].size()==0 || ms[2].size()==0) break;
}
cout<<-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
2260 KB |
Output is correct |
27 |
Correct |
6 ms |
2236 KB |
Output is correct |
28 |
Correct |
9 ms |
2280 KB |
Output is correct |
29 |
Correct |
9 ms |
2132 KB |
Output is correct |
30 |
Correct |
5 ms |
1620 KB |
Output is correct |
31 |
Correct |
6 ms |
2260 KB |
Output is correct |
32 |
Correct |
7 ms |
1776 KB |
Output is correct |
33 |
Correct |
5 ms |
1620 KB |
Output is correct |
34 |
Correct |
6 ms |
2260 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
7 ms |
1824 KB |
Output is correct |
38 |
Correct |
5 ms |
1748 KB |
Output is correct |
39 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
25740 KB |
Output is correct |
12 |
Correct |
100 ms |
17216 KB |
Output is correct |
13 |
Correct |
103 ms |
20796 KB |
Output is correct |
14 |
Correct |
170 ms |
25536 KB |
Output is correct |
15 |
Correct |
143 ms |
26156 KB |
Output is correct |
16 |
Correct |
127 ms |
27124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
25740 KB |
Output is correct |
12 |
Correct |
100 ms |
17216 KB |
Output is correct |
13 |
Correct |
103 ms |
20796 KB |
Output is correct |
14 |
Correct |
170 ms |
25536 KB |
Output is correct |
15 |
Correct |
143 ms |
26156 KB |
Output is correct |
16 |
Correct |
127 ms |
27124 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
209 ms |
26088 KB |
Output is correct |
23 |
Correct |
199 ms |
25004 KB |
Output is correct |
24 |
Correct |
139 ms |
18904 KB |
Output is correct |
25 |
Correct |
239 ms |
25916 KB |
Output is correct |
26 |
Correct |
174 ms |
26228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
25740 KB |
Output is correct |
12 |
Correct |
100 ms |
17216 KB |
Output is correct |
13 |
Correct |
103 ms |
20796 KB |
Output is correct |
14 |
Correct |
170 ms |
25536 KB |
Output is correct |
15 |
Correct |
143 ms |
26156 KB |
Output is correct |
16 |
Correct |
127 ms |
27124 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
209 ms |
26088 KB |
Output is correct |
23 |
Correct |
199 ms |
25004 KB |
Output is correct |
24 |
Correct |
139 ms |
18904 KB |
Output is correct |
25 |
Correct |
239 ms |
25916 KB |
Output is correct |
26 |
Correct |
174 ms |
26228 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 |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
7 ms |
1860 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
610 ms |
45784 KB |
Output is correct |
35 |
Correct |
503 ms |
39024 KB |
Output is correct |
36 |
Correct |
635 ms |
39392 KB |
Output is correct |
37 |
Correct |
627 ms |
38284 KB |
Output is correct |
38 |
Correct |
177 ms |
26248 KB |
Output is correct |
39 |
Correct |
134 ms |
25204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
25740 KB |
Output is correct |
12 |
Correct |
100 ms |
17216 KB |
Output is correct |
13 |
Correct |
103 ms |
20796 KB |
Output is correct |
14 |
Correct |
170 ms |
25536 KB |
Output is correct |
15 |
Correct |
143 ms |
26156 KB |
Output is correct |
16 |
Correct |
127 ms |
27124 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
209 ms |
26088 KB |
Output is correct |
23 |
Correct |
199 ms |
25004 KB |
Output is correct |
24 |
Correct |
139 ms |
18904 KB |
Output is correct |
25 |
Correct |
239 ms |
25916 KB |
Output is correct |
26 |
Correct |
174 ms |
26228 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 |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
7 ms |
1860 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
610 ms |
45784 KB |
Output is correct |
35 |
Correct |
503 ms |
39024 KB |
Output is correct |
36 |
Correct |
635 ms |
39392 KB |
Output is correct |
37 |
Correct |
627 ms |
38284 KB |
Output is correct |
38 |
Correct |
177 ms |
26248 KB |
Output is correct |
39 |
Correct |
134 ms |
25204 KB |
Output is correct |
40 |
Correct |
5 ms |
1620 KB |
Output is correct |
41 |
Correct |
8 ms |
2248 KB |
Output is correct |
42 |
Correct |
4 ms |
1748 KB |
Output is correct |
43 |
Correct |
7 ms |
1748 KB |
Output is correct |
44 |
Correct |
893 ms |
72284 KB |
Output is correct |
45 |
Correct |
928 ms |
59100 KB |
Output is correct |
46 |
Correct |
891 ms |
63404 KB |
Output is correct |
47 |
Correct |
967 ms |
57888 KB |
Output is correct |
48 |
Correct |
276 ms |
27944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
2260 KB |
Output is correct |
27 |
Correct |
6 ms |
2236 KB |
Output is correct |
28 |
Correct |
9 ms |
2280 KB |
Output is correct |
29 |
Correct |
9 ms |
2132 KB |
Output is correct |
30 |
Correct |
5 ms |
1620 KB |
Output is correct |
31 |
Correct |
6 ms |
2260 KB |
Output is correct |
32 |
Correct |
7 ms |
1776 KB |
Output is correct |
33 |
Correct |
5 ms |
1620 KB |
Output is correct |
34 |
Correct |
6 ms |
2260 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
7 ms |
1824 KB |
Output is correct |
38 |
Correct |
5 ms |
1748 KB |
Output is correct |
39 |
Correct |
2 ms |
724 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
166 ms |
25740 KB |
Output is correct |
51 |
Correct |
100 ms |
17216 KB |
Output is correct |
52 |
Correct |
103 ms |
20796 KB |
Output is correct |
53 |
Correct |
170 ms |
25536 KB |
Output is correct |
54 |
Correct |
143 ms |
26156 KB |
Output is correct |
55 |
Correct |
127 ms |
27124 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
724 KB |
Output is correct |
61 |
Correct |
209 ms |
26088 KB |
Output is correct |
62 |
Correct |
199 ms |
25004 KB |
Output is correct |
63 |
Correct |
139 ms |
18904 KB |
Output is correct |
64 |
Correct |
239 ms |
25916 KB |
Output is correct |
65 |
Correct |
174 ms |
26228 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 |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
7 ms |
1860 KB |
Output is correct |
71 |
Correct |
1 ms |
596 KB |
Output is correct |
72 |
Correct |
1 ms |
596 KB |
Output is correct |
73 |
Correct |
610 ms |
45784 KB |
Output is correct |
74 |
Correct |
503 ms |
39024 KB |
Output is correct |
75 |
Correct |
635 ms |
39392 KB |
Output is correct |
76 |
Correct |
627 ms |
38284 KB |
Output is correct |
77 |
Correct |
177 ms |
26248 KB |
Output is correct |
78 |
Correct |
134 ms |
25204 KB |
Output is correct |
79 |
Correct |
5 ms |
1620 KB |
Output is correct |
80 |
Correct |
8 ms |
2248 KB |
Output is correct |
81 |
Correct |
4 ms |
1748 KB |
Output is correct |
82 |
Correct |
7 ms |
1748 KB |
Output is correct |
83 |
Correct |
893 ms |
72284 KB |
Output is correct |
84 |
Correct |
928 ms |
59100 KB |
Output is correct |
85 |
Correct |
891 ms |
63404 KB |
Output is correct |
86 |
Correct |
967 ms |
57888 KB |
Output is correct |
87 |
Correct |
276 ms |
27944 KB |
Output is correct |
88 |
Correct |
856 ms |
72416 KB |
Output is correct |
89 |
Correct |
916 ms |
70680 KB |
Output is correct |
90 |
Correct |
876 ms |
72316 KB |
Output is correct |
91 |
Correct |
978 ms |
69236 KB |
Output is correct |
92 |
Correct |
896 ms |
71208 KB |
Output is correct |
93 |
Correct |
968 ms |
70868 KB |
Output is correct |
94 |
Correct |
1044 ms |
67440 KB |
Output is correct |
95 |
Correct |
454 ms |
49860 KB |
Output is correct |
96 |
Correct |
494 ms |
72652 KB |
Output is correct |
97 |
Correct |
146 ms |
27176 KB |
Output is correct |
98 |
Correct |
287 ms |
56136 KB |
Output is correct |
99 |
Correct |
382 ms |
56252 KB |
Output is correct |