#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int N = 2e5 + 2, MOD = 998244353;
int a[N],b[N],c[N],n;
set<pair<int,int>> x,y,z;
void del(int i) {
x.erase({a[i],i});
y.erase({b[i],i});
z.erase({c[i],i});
}
void test() {
cin >> n;
for(int i = 1;i <= n;i++) {
cin >> a[i] >> b[i] >> c[i];
x.insert({a[i],i});
y.insert({b[i],i});
z.insert({c[i],i});
}
while(true) {
if(x.empty()) {
cout << -1;
return;
}
auto [v,i] = (*x.rbegin());
auto [v1,j] = (*y.rbegin());
auto [v2,k] = (*z.rbegin());
auto bad = [&](int id)->bool{
int col = 0;
if(a[id] == (*x.rbegin()).first) col++;
if(b[id] == (*y.rbegin()).first) col++;
if(c[id] == (*z.rbegin()).first) col++;
if(col > 1) return 1;
return 0;
};
if(i == j && j == k) {
del(i);
continue;
}
if(i == j || i == k) {
del(i);
continue;
} else if(j == k) {
del(j);
continue;
}
bool ok = 1;
if(bad(i)) {
ok = false;
del(i);
}
if(bad(j)) {
ok = false;
del(j);
}
if(bad(k)) {
ok = false;
del(k);
}
if(ok) {
cout << v + v1 + v2;
return;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int t = 1;
// cin >> t;
while(t--) {
test();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4568 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4560 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4568 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4560 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
26 |
Correct |
4 ms |
5212 KB |
Output is correct |
27 |
Correct |
4 ms |
5304 KB |
Output is correct |
28 |
Correct |
4 ms |
5212 KB |
Output is correct |
29 |
Correct |
4 ms |
5212 KB |
Output is correct |
30 |
Correct |
3 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
5212 KB |
Output is correct |
32 |
Correct |
5 ms |
5212 KB |
Output is correct |
33 |
Correct |
3 ms |
5308 KB |
Output is correct |
34 |
Correct |
3 ms |
5212 KB |
Output is correct |
35 |
Correct |
1 ms |
4708 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
3 ms |
5288 KB |
Output is correct |
38 |
Correct |
5 ms |
5208 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
141 ms |
33000 KB |
Output is correct |
12 |
Correct |
116 ms |
22164 KB |
Output is correct |
13 |
Correct |
103 ms |
28644 KB |
Output is correct |
14 |
Correct |
197 ms |
33740 KB |
Output is correct |
15 |
Correct |
135 ms |
33624 KB |
Output is correct |
16 |
Correct |
136 ms |
33620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
141 ms |
33000 KB |
Output is correct |
12 |
Correct |
116 ms |
22164 KB |
Output is correct |
13 |
Correct |
103 ms |
28644 KB |
Output is correct |
14 |
Correct |
197 ms |
33740 KB |
Output is correct |
15 |
Correct |
135 ms |
33624 KB |
Output is correct |
16 |
Correct |
136 ms |
33620 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
154 ms |
33508 KB |
Output is correct |
23 |
Correct |
170 ms |
32584 KB |
Output is correct |
24 |
Correct |
197 ms |
25832 KB |
Output is correct |
25 |
Correct |
233 ms |
33992 KB |
Output is correct |
26 |
Correct |
151 ms |
33764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
141 ms |
33000 KB |
Output is correct |
12 |
Correct |
116 ms |
22164 KB |
Output is correct |
13 |
Correct |
103 ms |
28644 KB |
Output is correct |
14 |
Correct |
197 ms |
33740 KB |
Output is correct |
15 |
Correct |
135 ms |
33624 KB |
Output is correct |
16 |
Correct |
136 ms |
33620 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
154 ms |
33508 KB |
Output is correct |
23 |
Correct |
170 ms |
32584 KB |
Output is correct |
24 |
Correct |
197 ms |
25832 KB |
Output is correct |
25 |
Correct |
233 ms |
33992 KB |
Output is correct |
26 |
Correct |
151 ms |
33764 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
5 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
4700 KB |
Output is correct |
33 |
Correct |
1 ms |
476 KB |
Output is correct |
34 |
Correct |
252 ms |
32916 KB |
Output is correct |
35 |
Correct |
268 ms |
31568 KB |
Output is correct |
36 |
Correct |
299 ms |
33928 KB |
Output is correct |
37 |
Correct |
337 ms |
34284 KB |
Output is correct |
38 |
Correct |
162 ms |
33620 KB |
Output is correct |
39 |
Correct |
88 ms |
22608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
141 ms |
33000 KB |
Output is correct |
12 |
Correct |
116 ms |
22164 KB |
Output is correct |
13 |
Correct |
103 ms |
28644 KB |
Output is correct |
14 |
Correct |
197 ms |
33740 KB |
Output is correct |
15 |
Correct |
135 ms |
33624 KB |
Output is correct |
16 |
Correct |
136 ms |
33620 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
154 ms |
33508 KB |
Output is correct |
23 |
Correct |
170 ms |
32584 KB |
Output is correct |
24 |
Correct |
197 ms |
25832 KB |
Output is correct |
25 |
Correct |
233 ms |
33992 KB |
Output is correct |
26 |
Correct |
151 ms |
33764 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
5 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
4700 KB |
Output is correct |
33 |
Correct |
1 ms |
476 KB |
Output is correct |
34 |
Correct |
252 ms |
32916 KB |
Output is correct |
35 |
Correct |
268 ms |
31568 KB |
Output is correct |
36 |
Correct |
299 ms |
33928 KB |
Output is correct |
37 |
Correct |
337 ms |
34284 KB |
Output is correct |
38 |
Correct |
162 ms |
33620 KB |
Output is correct |
39 |
Correct |
88 ms |
22608 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
4 ms |
5212 KB |
Output is correct |
42 |
Correct |
3 ms |
5208 KB |
Output is correct |
43 |
Correct |
3 ms |
5212 KB |
Output is correct |
44 |
Correct |
235 ms |
34784 KB |
Output is correct |
45 |
Correct |
336 ms |
34900 KB |
Output is correct |
46 |
Correct |
295 ms |
34952 KB |
Output is correct |
47 |
Correct |
322 ms |
34852 KB |
Output is correct |
48 |
Correct |
184 ms |
34880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4568 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4560 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
26 |
Correct |
4 ms |
5212 KB |
Output is correct |
27 |
Correct |
4 ms |
5304 KB |
Output is correct |
28 |
Correct |
4 ms |
5212 KB |
Output is correct |
29 |
Correct |
4 ms |
5212 KB |
Output is correct |
30 |
Correct |
3 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
5212 KB |
Output is correct |
32 |
Correct |
5 ms |
5212 KB |
Output is correct |
33 |
Correct |
3 ms |
5308 KB |
Output is correct |
34 |
Correct |
3 ms |
5212 KB |
Output is correct |
35 |
Correct |
1 ms |
4708 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
3 ms |
5288 KB |
Output is correct |
38 |
Correct |
5 ms |
5208 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4440 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
464 KB |
Output is correct |
44 |
Correct |
1 ms |
344 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 |
0 ms |
460 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
141 ms |
33000 KB |
Output is correct |
51 |
Correct |
116 ms |
22164 KB |
Output is correct |
52 |
Correct |
103 ms |
28644 KB |
Output is correct |
53 |
Correct |
197 ms |
33740 KB |
Output is correct |
54 |
Correct |
135 ms |
33624 KB |
Output is correct |
55 |
Correct |
136 ms |
33620 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
58 |
Correct |
1 ms |
4444 KB |
Output is correct |
59 |
Correct |
1 ms |
4444 KB |
Output is correct |
60 |
Correct |
2 ms |
4956 KB |
Output is correct |
61 |
Correct |
154 ms |
33508 KB |
Output is correct |
62 |
Correct |
170 ms |
32584 KB |
Output is correct |
63 |
Correct |
197 ms |
25832 KB |
Output is correct |
64 |
Correct |
233 ms |
33992 KB |
Output is correct |
65 |
Correct |
151 ms |
33764 KB |
Output is correct |
66 |
Correct |
1 ms |
4444 KB |
Output is correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Correct |
1 ms |
4444 KB |
Output is correct |
69 |
Correct |
1 ms |
2396 KB |
Output is correct |
70 |
Correct |
5 ms |
1372 KB |
Output is correct |
71 |
Correct |
1 ms |
4700 KB |
Output is correct |
72 |
Correct |
1 ms |
476 KB |
Output is correct |
73 |
Correct |
252 ms |
32916 KB |
Output is correct |
74 |
Correct |
268 ms |
31568 KB |
Output is correct |
75 |
Correct |
299 ms |
33928 KB |
Output is correct |
76 |
Correct |
337 ms |
34284 KB |
Output is correct |
77 |
Correct |
162 ms |
33620 KB |
Output is correct |
78 |
Correct |
88 ms |
22608 KB |
Output is correct |
79 |
Correct |
3 ms |
4956 KB |
Output is correct |
80 |
Correct |
4 ms |
5212 KB |
Output is correct |
81 |
Correct |
3 ms |
5208 KB |
Output is correct |
82 |
Correct |
3 ms |
5212 KB |
Output is correct |
83 |
Correct |
235 ms |
34784 KB |
Output is correct |
84 |
Correct |
336 ms |
34900 KB |
Output is correct |
85 |
Correct |
295 ms |
34952 KB |
Output is correct |
86 |
Correct |
322 ms |
34852 KB |
Output is correct |
87 |
Correct |
184 ms |
34880 KB |
Output is correct |
88 |
Correct |
231 ms |
36840 KB |
Output is correct |
89 |
Correct |
295 ms |
36704 KB |
Output is correct |
90 |
Correct |
249 ms |
36688 KB |
Output is correct |
91 |
Correct |
304 ms |
36688 KB |
Output is correct |
92 |
Correct |
243 ms |
35296 KB |
Output is correct |
93 |
Correct |
295 ms |
35508 KB |
Output is correct |
94 |
Correct |
298 ms |
35664 KB |
Output is correct |
95 |
Correct |
194 ms |
36552 KB |
Output is correct |
96 |
Correct |
163 ms |
36816 KB |
Output is correct |
97 |
Correct |
144 ms |
36772 KB |
Output is correct |
98 |
Correct |
110 ms |
35388 KB |
Output is correct |
99 |
Correct |
140 ms |
35396 KB |
Output is correct |