#include <bits/stdc++.h>
using namespace std;
struct abc {
int a, b, c, bestB, bestC;
};
const int MAX_N = 2e5;
const int INF = 1e8;
abc v[MAX_N];
struct AIB {
unordered_map<int, int> aib;
void init() {
aib.clear();
}
void update( int i, int x ) {
while ( i <= MAX_N ) {
aib[i] = max( aib[i], x );
i += (i & -i);
}
}
int query( int i ) {
int ans = 0;
while ( i > 0 ) {
ans = max( ans, aib[i] );
i -= (i & -i);
}
return (ans == 0 ? -INF : ans);
}
} aib;
map<int, int> normA, normB, normC;
int main() {
ios_base::sync_with_stdio( false );
cin.tie( NULL );
int n;
cin >> n;
for ( int i = 0; i < n; i++ )
cin >> v[i].a >> v[i].b >> v[i].c;
for ( int i = 0; i < n; i++ ) {
normA[v[i].a] = 1;
normB[v[i].b] = 1;
normC[v[i].c] = 1;
}
int x;
x = 0;
for ( auto p: normA )
normA[p.first] = ++x;
x = 0;
for ( auto p: normB )
normB[p.first] = ++x;
x = 0;
for ( auto p: normC )
normC[p.first] = ++x;
int ans = -1, l, r;
///BC
sort( v, v + n, []( abc a, abc b ) {
if ( a.a == b.a )
return a.b < b.b;
return a.a < b.a;
} );
aib.init();
for ( int i = 0; i < n; i++ ) {
v[i].bestC = aib.query( normB[v[i].b] - 1 );
aib.update( normB[v[i].b], v[i].c );
}
sort( v, v + n, []( abc a, abc b ) {
return a.b < b.b;
} );
aib.init();
l = r = 0;
while ( l < n ) {
r = l;
while ( r < n && v[l].b == v[r].b )
r++;
for ( int i = l; i < r; i++ ) {
if ( v[i].bestC > v[i].c ) {
int a = aib.query( normC[v[i].bestC] - 1 );
if ( a > v[i].a )
ans = max( ans, a + v[i].b + v[i].bestC );
}
}
for ( int i = l; i < r; i++ )
aib.update( normC[v[i].c], v[i].a );
l = r;
}
///CB
sort( v, v + n, []( abc a, abc b ) {
if ( a.a == b.a )
return a.c < b.c;
return a.a < b.a;
} );
aib.init();
for ( int i = 0; i < n; i++ ) {
v[i].bestB = aib.query( normC[v[i].c] - 1 );
aib.update( normC[v[i].c], v[i].b );
}
sort( v, v + n, []( abc a, abc b ) {
return a.c < b.c;
} );
aib.init();
l = r = 0;
while ( l < n ) {
r = l;
while ( r < n && v[l].c == v[r].c )
r++;
for ( int i = l; i < r; i++ ) {
if ( v[i].bestB > v[i].b ) {
int a = aib.query( normB[v[i].bestB] - 1 );
if ( a > v[i].a )
ans = max( ans, a + v[i].bestB + v[i].c );
}
}
for ( int i = l; i < r; i++ )
aib.update( normB[v[i].b], v[i].a );
l = r;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
344 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
348 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
344 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
348 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 |
348 KB |
Output is correct |
26 |
Correct |
10 ms |
1112 KB |
Output is correct |
27 |
Correct |
9 ms |
860 KB |
Output is correct |
28 |
Correct |
9 ms |
964 KB |
Output is correct |
29 |
Correct |
8 ms |
860 KB |
Output is correct |
30 |
Correct |
5 ms |
604 KB |
Output is correct |
31 |
Correct |
7 ms |
604 KB |
Output is correct |
32 |
Correct |
6 ms |
604 KB |
Output is correct |
33 |
Correct |
6 ms |
604 KB |
Output is correct |
34 |
Correct |
8 ms |
1120 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
6 ms |
744 KB |
Output is correct |
38 |
Correct |
5 ms |
604 KB |
Output is correct |
39 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
3376 KB |
Output is correct |
12 |
Correct |
107 ms |
2652 KB |
Output is correct |
13 |
Correct |
125 ms |
2652 KB |
Output is correct |
14 |
Correct |
153 ms |
3160 KB |
Output is correct |
15 |
Correct |
153 ms |
3372 KB |
Output is correct |
16 |
Correct |
140 ms |
3372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
3376 KB |
Output is correct |
12 |
Correct |
107 ms |
2652 KB |
Output is correct |
13 |
Correct |
125 ms |
2652 KB |
Output is correct |
14 |
Correct |
153 ms |
3160 KB |
Output is correct |
15 |
Correct |
153 ms |
3372 KB |
Output is correct |
16 |
Correct |
140 ms |
3372 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
179 ms |
3380 KB |
Output is correct |
23 |
Correct |
179 ms |
3168 KB |
Output is correct |
24 |
Correct |
120 ms |
2680 KB |
Output is correct |
25 |
Correct |
164 ms |
3372 KB |
Output is correct |
26 |
Correct |
153 ms |
3376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
3376 KB |
Output is correct |
12 |
Correct |
107 ms |
2652 KB |
Output is correct |
13 |
Correct |
125 ms |
2652 KB |
Output is correct |
14 |
Correct |
153 ms |
3160 KB |
Output is correct |
15 |
Correct |
153 ms |
3372 KB |
Output is correct |
16 |
Correct |
140 ms |
3372 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
179 ms |
3380 KB |
Output is correct |
23 |
Correct |
179 ms |
3168 KB |
Output is correct |
24 |
Correct |
120 ms |
2680 KB |
Output is correct |
25 |
Correct |
164 ms |
3372 KB |
Output is correct |
26 |
Correct |
153 ms |
3376 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
6 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
544 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
195 ms |
3296 KB |
Output is correct |
35 |
Correct |
188 ms |
3156 KB |
Output is correct |
36 |
Correct |
205 ms |
3432 KB |
Output is correct |
37 |
Correct |
196 ms |
3408 KB |
Output is correct |
38 |
Correct |
163 ms |
3352 KB |
Output is correct |
39 |
Correct |
99 ms |
2696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
3376 KB |
Output is correct |
12 |
Correct |
107 ms |
2652 KB |
Output is correct |
13 |
Correct |
125 ms |
2652 KB |
Output is correct |
14 |
Correct |
153 ms |
3160 KB |
Output is correct |
15 |
Correct |
153 ms |
3372 KB |
Output is correct |
16 |
Correct |
140 ms |
3372 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
179 ms |
3380 KB |
Output is correct |
23 |
Correct |
179 ms |
3168 KB |
Output is correct |
24 |
Correct |
120 ms |
2680 KB |
Output is correct |
25 |
Correct |
164 ms |
3372 KB |
Output is correct |
26 |
Correct |
153 ms |
3376 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
6 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
544 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
195 ms |
3296 KB |
Output is correct |
35 |
Correct |
188 ms |
3156 KB |
Output is correct |
36 |
Correct |
205 ms |
3432 KB |
Output is correct |
37 |
Correct |
196 ms |
3408 KB |
Output is correct |
38 |
Correct |
163 ms |
3352 KB |
Output is correct |
39 |
Correct |
99 ms |
2696 KB |
Output is correct |
40 |
Correct |
6 ms |
604 KB |
Output is correct |
41 |
Correct |
7 ms |
604 KB |
Output is correct |
42 |
Correct |
6 ms |
600 KB |
Output is correct |
43 |
Correct |
5 ms |
600 KB |
Output is correct |
44 |
Correct |
308 ms |
4276 KB |
Output is correct |
45 |
Correct |
254 ms |
4040 KB |
Output is correct |
46 |
Correct |
285 ms |
3924 KB |
Output is correct |
47 |
Correct |
257 ms |
4112 KB |
Output is correct |
48 |
Correct |
158 ms |
3664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
344 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
348 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 |
348 KB |
Output is correct |
26 |
Correct |
10 ms |
1112 KB |
Output is correct |
27 |
Correct |
9 ms |
860 KB |
Output is correct |
28 |
Correct |
9 ms |
964 KB |
Output is correct |
29 |
Correct |
8 ms |
860 KB |
Output is correct |
30 |
Correct |
5 ms |
604 KB |
Output is correct |
31 |
Correct |
7 ms |
604 KB |
Output is correct |
32 |
Correct |
6 ms |
604 KB |
Output is correct |
33 |
Correct |
6 ms |
604 KB |
Output is correct |
34 |
Correct |
8 ms |
1120 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
6 ms |
744 KB |
Output is correct |
38 |
Correct |
5 ms |
604 KB |
Output is correct |
39 |
Correct |
3 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 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 |
348 KB |
Output is correct |
45 |
Correct |
0 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 |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
160 ms |
3376 KB |
Output is correct |
51 |
Correct |
107 ms |
2652 KB |
Output is correct |
52 |
Correct |
125 ms |
2652 KB |
Output is correct |
53 |
Correct |
153 ms |
3160 KB |
Output is correct |
54 |
Correct |
153 ms |
3372 KB |
Output is correct |
55 |
Correct |
140 ms |
3372 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
1 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 |
3 ms |
348 KB |
Output is correct |
61 |
Correct |
179 ms |
3380 KB |
Output is correct |
62 |
Correct |
179 ms |
3168 KB |
Output is correct |
63 |
Correct |
120 ms |
2680 KB |
Output is correct |
64 |
Correct |
164 ms |
3372 KB |
Output is correct |
65 |
Correct |
153 ms |
3376 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
344 KB |
Output is correct |
68 |
Correct |
1 ms |
344 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
6 ms |
600 KB |
Output is correct |
71 |
Correct |
1 ms |
544 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
195 ms |
3296 KB |
Output is correct |
74 |
Correct |
188 ms |
3156 KB |
Output is correct |
75 |
Correct |
205 ms |
3432 KB |
Output is correct |
76 |
Correct |
196 ms |
3408 KB |
Output is correct |
77 |
Correct |
163 ms |
3352 KB |
Output is correct |
78 |
Correct |
99 ms |
2696 KB |
Output is correct |
79 |
Correct |
6 ms |
604 KB |
Output is correct |
80 |
Correct |
7 ms |
604 KB |
Output is correct |
81 |
Correct |
6 ms |
600 KB |
Output is correct |
82 |
Correct |
5 ms |
600 KB |
Output is correct |
83 |
Correct |
308 ms |
4276 KB |
Output is correct |
84 |
Correct |
254 ms |
4040 KB |
Output is correct |
85 |
Correct |
285 ms |
3924 KB |
Output is correct |
86 |
Correct |
257 ms |
4112 KB |
Output is correct |
87 |
Correct |
158 ms |
3664 KB |
Output is correct |
88 |
Correct |
925 ms |
30556 KB |
Output is correct |
89 |
Correct |
539 ms |
22272 KB |
Output is correct |
90 |
Correct |
641 ms |
24960 KB |
Output is correct |
91 |
Correct |
445 ms |
19404 KB |
Output is correct |
92 |
Correct |
397 ms |
10924 KB |
Output is correct |
93 |
Correct |
580 ms |
23204 KB |
Output is correct |
94 |
Correct |
424 ms |
16040 KB |
Output is correct |
95 |
Correct |
211 ms |
13744 KB |
Output is correct |
96 |
Correct |
435 ms |
34420 KB |
Output is correct |
97 |
Correct |
163 ms |
7128 KB |
Output is correct |
98 |
Correct |
191 ms |
15352 KB |
Output is correct |
99 |
Correct |
194 ms |
15280 KB |
Output is correct |