#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define opa(x) cout << #x << " = " << x << ", ";
#define op(x) cout << #x << " = " << x << endl;
#define ops(x) cout << x;
#define entr cout << endl;
#define spac cout << ' ';
#define all(x) (x).begin(), (x).end()
#define STL(x) cout << #x << " : "; for(auto &qwe:x) cout << qwe << ' '; cout << endl;
#define deb1 cout << "deb1" << endl;
#define deb2 cout << "deb2" << endl;
#define deb3 cout << "deb3" << endl;
#define deb4 cout << "deb4" << endl;
#define deb5 cout << "deb5" << endl;
using namespace std;
const int mxn = 150010;
int a[mxn], b[mxn], c[mxn];
multiset<pii, greater<pii>> a_srt, b_srt, c_srt;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
// freopen("test_input.txt", "r", stdin);
int n; cin >> n;
loop(i,0,n){
int ina, inb, inc;
cin >> ina >> inb >> inc;
a[i] = ina;
b[i] = inb;
c[i] = inc;
a_srt.insert({ina, i});
b_srt.insert({inb, i});
c_srt.insert({inc, i});
}
auto remov = [&](int ind){
a_srt.erase({a[ind], ind});
b_srt.erase({b[ind], ind});
c_srt.erase({c[ind], ind});
};
loop(i,0,n){
int now = a_srt.begin()->ss;
if(b[now] == b_srt.begin()->ff || c[now] == c_srt.begin()->ff){
remov(now);
continue;
}
now = b_srt.begin()->ss;
if(a[now] == a_srt.begin()->ff || c[now] == c_srt.begin()->ff){
remov(now);
continue;
}
now = c_srt.begin()->ss;
if(a[now] == a_srt.begin()->ff || b[now] == b_srt.begin()->ff){
remov(now);
continue;
}
cout << a_srt.begin()->ff + b_srt.begin()->ff + c_srt.begin()->ff << '\n';
return 0;
}
cout << "-1\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
472 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
472 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1188 KB |
Output is correct |
28 |
Correct |
4 ms |
1116 KB |
Output is correct |
29 |
Correct |
4 ms |
992 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
1116 KB |
Output is correct |
32 |
Correct |
4 ms |
1116 KB |
Output is correct |
33 |
Correct |
4 ms |
1116 KB |
Output is correct |
34 |
Correct |
3 ms |
1188 KB |
Output is correct |
35 |
Correct |
1 ms |
800 KB |
Output is correct |
36 |
Correct |
1 ms |
628 KB |
Output is correct |
37 |
Correct |
2 ms |
1116 KB |
Output is correct |
38 |
Correct |
3 ms |
1008 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
125 ms |
24540 KB |
Output is correct |
12 |
Correct |
97 ms |
16212 KB |
Output is correct |
13 |
Correct |
82 ms |
19796 KB |
Output is correct |
14 |
Correct |
157 ms |
24112 KB |
Output is correct |
15 |
Correct |
130 ms |
24396 KB |
Output is correct |
16 |
Correct |
112 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
125 ms |
24540 KB |
Output is correct |
12 |
Correct |
97 ms |
16212 KB |
Output is correct |
13 |
Correct |
82 ms |
19796 KB |
Output is correct |
14 |
Correct |
157 ms |
24112 KB |
Output is correct |
15 |
Correct |
130 ms |
24396 KB |
Output is correct |
16 |
Correct |
112 ms |
24148 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
736 KB |
Output is correct |
22 |
Correct |
179 ms |
24404 KB |
Output is correct |
23 |
Correct |
141 ms |
23720 KB |
Output is correct |
24 |
Correct |
126 ms |
17748 KB |
Output is correct |
25 |
Correct |
232 ms |
24404 KB |
Output is correct |
26 |
Correct |
144 ms |
24248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
125 ms |
24540 KB |
Output is correct |
12 |
Correct |
97 ms |
16212 KB |
Output is correct |
13 |
Correct |
82 ms |
19796 KB |
Output is correct |
14 |
Correct |
157 ms |
24112 KB |
Output is correct |
15 |
Correct |
130 ms |
24396 KB |
Output is correct |
16 |
Correct |
112 ms |
24148 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
736 KB |
Output is correct |
22 |
Correct |
179 ms |
24404 KB |
Output is correct |
23 |
Correct |
141 ms |
23720 KB |
Output is correct |
24 |
Correct |
126 ms |
17748 KB |
Output is correct |
25 |
Correct |
232 ms |
24404 KB |
Output is correct |
26 |
Correct |
144 ms |
24248 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
476 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
203 ms |
23768 KB |
Output is correct |
35 |
Correct |
240 ms |
22612 KB |
Output is correct |
36 |
Correct |
256 ms |
24748 KB |
Output is correct |
37 |
Correct |
318 ms |
25056 KB |
Output is correct |
38 |
Correct |
165 ms |
24136 KB |
Output is correct |
39 |
Correct |
69 ms |
15060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
125 ms |
24540 KB |
Output is correct |
12 |
Correct |
97 ms |
16212 KB |
Output is correct |
13 |
Correct |
82 ms |
19796 KB |
Output is correct |
14 |
Correct |
157 ms |
24112 KB |
Output is correct |
15 |
Correct |
130 ms |
24396 KB |
Output is correct |
16 |
Correct |
112 ms |
24148 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
736 KB |
Output is correct |
22 |
Correct |
179 ms |
24404 KB |
Output is correct |
23 |
Correct |
141 ms |
23720 KB |
Output is correct |
24 |
Correct |
126 ms |
17748 KB |
Output is correct |
25 |
Correct |
232 ms |
24404 KB |
Output is correct |
26 |
Correct |
144 ms |
24248 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
476 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
203 ms |
23768 KB |
Output is correct |
35 |
Correct |
240 ms |
22612 KB |
Output is correct |
36 |
Correct |
256 ms |
24748 KB |
Output is correct |
37 |
Correct |
318 ms |
25056 KB |
Output is correct |
38 |
Correct |
165 ms |
24136 KB |
Output is correct |
39 |
Correct |
69 ms |
15060 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
4 ms |
1116 KB |
Output is correct |
42 |
Correct |
2 ms |
1112 KB |
Output is correct |
43 |
Correct |
3 ms |
1112 KB |
Output is correct |
44 |
Correct |
269 ms |
25380 KB |
Output is correct |
45 |
Correct |
325 ms |
25388 KB |
Output is correct |
46 |
Correct |
319 ms |
25172 KB |
Output is correct |
47 |
Correct |
355 ms |
25468 KB |
Output is correct |
48 |
Correct |
205 ms |
25140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
472 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1188 KB |
Output is correct |
28 |
Correct |
4 ms |
1116 KB |
Output is correct |
29 |
Correct |
4 ms |
992 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
1116 KB |
Output is correct |
32 |
Correct |
4 ms |
1116 KB |
Output is correct |
33 |
Correct |
4 ms |
1116 KB |
Output is correct |
34 |
Correct |
3 ms |
1188 KB |
Output is correct |
35 |
Correct |
1 ms |
800 KB |
Output is correct |
36 |
Correct |
1 ms |
628 KB |
Output is correct |
37 |
Correct |
2 ms |
1116 KB |
Output is correct |
38 |
Correct |
3 ms |
1008 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
472 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
125 ms |
24540 KB |
Output is correct |
51 |
Correct |
97 ms |
16212 KB |
Output is correct |
52 |
Correct |
82 ms |
19796 KB |
Output is correct |
53 |
Correct |
157 ms |
24112 KB |
Output is correct |
54 |
Correct |
130 ms |
24396 KB |
Output is correct |
55 |
Correct |
112 ms |
24148 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
736 KB |
Output is correct |
61 |
Correct |
179 ms |
24404 KB |
Output is correct |
62 |
Correct |
141 ms |
23720 KB |
Output is correct |
63 |
Correct |
126 ms |
17748 KB |
Output is correct |
64 |
Correct |
232 ms |
24404 KB |
Output is correct |
65 |
Correct |
144 ms |
24248 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
0 ms |
348 KB |
Output is correct |
70 |
Correct |
4 ms |
1116 KB |
Output is correct |
71 |
Correct |
1 ms |
476 KB |
Output is correct |
72 |
Correct |
1 ms |
604 KB |
Output is correct |
73 |
Correct |
203 ms |
23768 KB |
Output is correct |
74 |
Correct |
240 ms |
22612 KB |
Output is correct |
75 |
Correct |
256 ms |
24748 KB |
Output is correct |
76 |
Correct |
318 ms |
25056 KB |
Output is correct |
77 |
Correct |
165 ms |
24136 KB |
Output is correct |
78 |
Correct |
69 ms |
15060 KB |
Output is correct |
79 |
Correct |
2 ms |
856 KB |
Output is correct |
80 |
Correct |
4 ms |
1116 KB |
Output is correct |
81 |
Correct |
2 ms |
1112 KB |
Output is correct |
82 |
Correct |
3 ms |
1112 KB |
Output is correct |
83 |
Correct |
269 ms |
25380 KB |
Output is correct |
84 |
Correct |
325 ms |
25388 KB |
Output is correct |
85 |
Correct |
319 ms |
25172 KB |
Output is correct |
86 |
Correct |
355 ms |
25468 KB |
Output is correct |
87 |
Correct |
205 ms |
25140 KB |
Output is correct |
88 |
Correct |
285 ms |
27220 KB |
Output is correct |
89 |
Correct |
260 ms |
27096 KB |
Output is correct |
90 |
Correct |
275 ms |
27100 KB |
Output is correct |
91 |
Correct |
278 ms |
27020 KB |
Output is correct |
92 |
Correct |
282 ms |
25864 KB |
Output is correct |
93 |
Correct |
324 ms |
26068 KB |
Output is correct |
94 |
Correct |
369 ms |
25712 KB |
Output is correct |
95 |
Correct |
211 ms |
26964 KB |
Output is correct |
96 |
Correct |
189 ms |
27220 KB |
Output is correct |
97 |
Correct |
126 ms |
27220 KB |
Output is correct |
98 |
Correct |
106 ms |
25680 KB |
Output is correct |
99 |
Correct |
124 ms |
25624 KB |
Output is correct |