#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
struct Fenw{
vector <int> fenw;
int n;
Fenw(int n) : fenw(n + 1, 0), n(n) {}
void upd(int i, int val){
for (; i <= n; i += i & -i ){
chmax(fenw[i], val);
}
}
int get(int i){
int cnt = 0;
for (; i > 0; i -= i & -i ){
chmax(cnt, fenw[i]);
}
return cnt;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <int> X(n), Y(n), Z(n);
for ( int i = 0; i < n; i++ ){
cin >> X[i] >> Y[i] >> Z[i];
}
auto f = [&](auto X, auto Y, auto Z){
vector <int> p(n), pos;
for ( int i = 0; i < n; i++ ){
pos.pb(Y[i]);
p[i] = i;
}
sort(all(pos));
pos.resize(unique(all(pos)) - pos.begin());
sort(all(p), [&](int &u, int &v){
return X[u] < X[v];
});
auto get = [&](int x){
return lower_bound(all(pos), x) - pos.begin() + 1;
};
const int inf = 1e16;
vector <ar<int,2>> pf(n, {-inf, -1});
Fenw fn(n);
for ( int i = 0; i < n; i++ ){
int q = fn.get(get(Y[p[i]]) - 1);
if ( i ) pf[i] = pf[i - 1];
if ( q > Z[p[i]] ){
chmax(pf[i], ar<int,2>{q + Y[p[i]], Y[p[i]]});
}
fn.upd(get(Y[p[i]]), Z[p[i]]);
}
int opt = -1;
for ( int i = 0; i < n;){
int j = i;
while ( j < n && X[p[i]] == X[p[j]] ){
if ( i > 0 ){
int y = pf[i - 1][1], z = pf[i - 1][0] - y;
if ( y > Y[p[j]] && z > Z[p[j]] ){
chmax(opt, z + y + X[p[j]]);
}
} ++j;
} i = j;
}
return opt;
};
cout << max(f(X, Y, Z), f(X, Z, Y));
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
832 KB |
Output is correct |
27 |
Correct |
4 ms |
832 KB |
Output is correct |
28 |
Correct |
3 ms |
832 KB |
Output is correct |
29 |
Correct |
3 ms |
832 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
832 KB |
Output is correct |
32 |
Correct |
3 ms |
832 KB |
Output is correct |
33 |
Correct |
2 ms |
1112 KB |
Output is correct |
34 |
Correct |
3 ms |
832 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
1084 KB |
Output is correct |
38 |
Correct |
3 ms |
832 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 |
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 |
52 ms |
17536 KB |
Output is correct |
12 |
Correct |
39 ms |
11744 KB |
Output is correct |
13 |
Correct |
35 ms |
13840 KB |
Output is correct |
14 |
Correct |
53 ms |
17640 KB |
Output is correct |
15 |
Correct |
44 ms |
18672 KB |
Output is correct |
16 |
Correct |
40 ms |
17548 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 |
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 |
52 ms |
17536 KB |
Output is correct |
12 |
Correct |
39 ms |
11744 KB |
Output is correct |
13 |
Correct |
35 ms |
13840 KB |
Output is correct |
14 |
Correct |
53 ms |
17640 KB |
Output is correct |
15 |
Correct |
44 ms |
18672 KB |
Output is correct |
16 |
Correct |
40 ms |
17548 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
67 ms |
17704 KB |
Output is correct |
23 |
Correct |
57 ms |
17268 KB |
Output is correct |
24 |
Correct |
45 ms |
12388 KB |
Output is correct |
25 |
Correct |
62 ms |
17652 KB |
Output is correct |
26 |
Correct |
47 ms |
17684 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 |
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 |
52 ms |
17536 KB |
Output is correct |
12 |
Correct |
39 ms |
11744 KB |
Output is correct |
13 |
Correct |
35 ms |
13840 KB |
Output is correct |
14 |
Correct |
53 ms |
17640 KB |
Output is correct |
15 |
Correct |
44 ms |
18672 KB |
Output is correct |
16 |
Correct |
40 ms |
17548 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
67 ms |
17704 KB |
Output is correct |
23 |
Correct |
57 ms |
17268 KB |
Output is correct |
24 |
Correct |
45 ms |
12388 KB |
Output is correct |
25 |
Correct |
62 ms |
17652 KB |
Output is correct |
26 |
Correct |
47 ms |
17684 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
832 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
84 ms |
16892 KB |
Output is correct |
35 |
Correct |
76 ms |
16128 KB |
Output is correct |
36 |
Correct |
83 ms |
17700 KB |
Output is correct |
37 |
Correct |
87 ms |
17960 KB |
Output is correct |
38 |
Correct |
57 ms |
17252 KB |
Output is correct |
39 |
Correct |
30 ms |
10520 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 |
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 |
52 ms |
17536 KB |
Output is correct |
12 |
Correct |
39 ms |
11744 KB |
Output is correct |
13 |
Correct |
35 ms |
13840 KB |
Output is correct |
14 |
Correct |
53 ms |
17640 KB |
Output is correct |
15 |
Correct |
44 ms |
18672 KB |
Output is correct |
16 |
Correct |
40 ms |
17548 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
67 ms |
17704 KB |
Output is correct |
23 |
Correct |
57 ms |
17268 KB |
Output is correct |
24 |
Correct |
45 ms |
12388 KB |
Output is correct |
25 |
Correct |
62 ms |
17652 KB |
Output is correct |
26 |
Correct |
47 ms |
17684 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
832 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
84 ms |
16892 KB |
Output is correct |
35 |
Correct |
76 ms |
16128 KB |
Output is correct |
36 |
Correct |
83 ms |
17700 KB |
Output is correct |
37 |
Correct |
87 ms |
17960 KB |
Output is correct |
38 |
Correct |
57 ms |
17252 KB |
Output is correct |
39 |
Correct |
30 ms |
10520 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
3 ms |
832 KB |
Output is correct |
42 |
Correct |
2 ms |
832 KB |
Output is correct |
43 |
Correct |
3 ms |
832 KB |
Output is correct |
44 |
Correct |
122 ms |
17688 KB |
Output is correct |
45 |
Correct |
115 ms |
17868 KB |
Output is correct |
46 |
Correct |
116 ms |
17700 KB |
Output is correct |
47 |
Correct |
110 ms |
17716 KB |
Output is correct |
48 |
Correct |
69 ms |
17636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
832 KB |
Output is correct |
27 |
Correct |
4 ms |
832 KB |
Output is correct |
28 |
Correct |
3 ms |
832 KB |
Output is correct |
29 |
Correct |
3 ms |
832 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
832 KB |
Output is correct |
32 |
Correct |
3 ms |
832 KB |
Output is correct |
33 |
Correct |
2 ms |
1112 KB |
Output is correct |
34 |
Correct |
3 ms |
832 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
1084 KB |
Output is correct |
38 |
Correct |
3 ms |
832 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 |
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 |
52 ms |
17536 KB |
Output is correct |
51 |
Correct |
39 ms |
11744 KB |
Output is correct |
52 |
Correct |
35 ms |
13840 KB |
Output is correct |
53 |
Correct |
53 ms |
17640 KB |
Output is correct |
54 |
Correct |
44 ms |
18672 KB |
Output is correct |
55 |
Correct |
40 ms |
17548 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
604 KB |
Output is correct |
61 |
Correct |
67 ms |
17704 KB |
Output is correct |
62 |
Correct |
57 ms |
17268 KB |
Output is correct |
63 |
Correct |
45 ms |
12388 KB |
Output is correct |
64 |
Correct |
62 ms |
17652 KB |
Output is correct |
65 |
Correct |
47 ms |
17684 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
2 ms |
832 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
84 ms |
16892 KB |
Output is correct |
74 |
Correct |
76 ms |
16128 KB |
Output is correct |
75 |
Correct |
83 ms |
17700 KB |
Output is correct |
76 |
Correct |
87 ms |
17960 KB |
Output is correct |
77 |
Correct |
57 ms |
17252 KB |
Output is correct |
78 |
Correct |
30 ms |
10520 KB |
Output is correct |
79 |
Correct |
2 ms |
856 KB |
Output is correct |
80 |
Correct |
3 ms |
832 KB |
Output is correct |
81 |
Correct |
2 ms |
832 KB |
Output is correct |
82 |
Correct |
3 ms |
832 KB |
Output is correct |
83 |
Correct |
122 ms |
17688 KB |
Output is correct |
84 |
Correct |
115 ms |
17868 KB |
Output is correct |
85 |
Correct |
116 ms |
17700 KB |
Output is correct |
86 |
Correct |
110 ms |
17716 KB |
Output is correct |
87 |
Correct |
69 ms |
17636 KB |
Output is correct |
88 |
Correct |
182 ms |
17636 KB |
Output is correct |
89 |
Correct |
154 ms |
17636 KB |
Output is correct |
90 |
Correct |
162 ms |
17636 KB |
Output is correct |
91 |
Correct |
149 ms |
17672 KB |
Output is correct |
92 |
Correct |
142 ms |
17620 KB |
Output is correct |
93 |
Correct |
156 ms |
17624 KB |
Output is correct |
94 |
Correct |
141 ms |
17736 KB |
Output is correct |
95 |
Correct |
86 ms |
17640 KB |
Output is correct |
96 |
Correct |
120 ms |
17624 KB |
Output is correct |
97 |
Correct |
54 ms |
17640 KB |
Output is correct |
98 |
Correct |
73 ms |
17756 KB |
Output is correct |
99 |
Correct |
116 ms |
17928 KB |
Output is correct |