#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cmplx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cout << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cout << #arr; FR(_i, n) cout << ' ' << arr[_i]; cout << endl;}
typedef array<int, 3> trip;
const int MN = 150005;
int n;
vector<trip> vec;
vi ys, zs;
int mxZPref[MN], mxYPref[MN], mnYSuf[MN], mxAnsSuf[MN];
int main(){
boost();
cin >> n;
FR(i, n){
int a, b, c;
cin >> a >> b >> c;
vec.pb({a, b, c});
ys.pb(b);
zs.pb(c);
}
UNIQUE(vec);
UNIQUE(ys);
UNIQUE(zs);
n = SZ(ys);
int ans = -1;
int lst = 0, prvX = vec[0][0];
ms(mnYSuf, INF);
FR(i, SZ(vec)){
if(vec[i][0] != prvX){
FOR(j, lst, i){
auto [x, y, z] = vec[j];
int yPos = lbv(ys, y);
int zPos = lbv(zs, z);
int mz = 0;
for(int k = yPos; k; k -= k & -k) mz = max(mz, mxZPref[k]);
if(mz > z) for(int k = MN-yPos-1; k < MN; k += k & -k) mxAnsSuf[k] = max(mxAnsSuf[k], y + mz);
for(int k = zPos+1; k < MN; k += k & -k) mxYPref[k] = max(mxYPref[k], y);
for(int k = MN-zPos-1; k < MN; k += k & -k) mnYSuf[k] = min(mnYSuf[k], yPos);
int mxY = 0;
for(int k = zPos; k; k -= k & -k) mxY = max(mxY, mxYPref[k]);
if(mxY > y){
int yp1 = lbv(ys, mxY);
for(int k = MN-yp1-1; k < MN; k += k & -k) mxAnsSuf[k] = max(mxAnsSuf[k], mxY + z);
}
for(int k = yPos+1; k < MN; k += k & -k) mxZPref[k] = max(mxZPref[k], z);
}
prvX = vec[i][0];
lst = i;
}
auto [x, y, z] = vec[i];
int yPos = lbv(ys, y);
int zPos = lbv(zs, z);
int mnY = INF;
for(int j = MN-zPos-2; j; j -= j & -j) mnY = min(mnY, mnYSuf[j]);
int mxSum = 0;
for(int j = MN-2-max(yPos, mnY); j > 0; j -= j & -j) mxSum = max(mxSum, mxAnsSuf[j]);
if(mxSum) ans = max(ans, mxSum + x);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
5 ms |
1108 KB |
Output is correct |
27 |
Correct |
5 ms |
1108 KB |
Output is correct |
28 |
Correct |
4 ms |
1188 KB |
Output is correct |
29 |
Correct |
4 ms |
1108 KB |
Output is correct |
30 |
Correct |
3 ms |
1108 KB |
Output is correct |
31 |
Correct |
4 ms |
1108 KB |
Output is correct |
32 |
Correct |
3 ms |
1112 KB |
Output is correct |
33 |
Correct |
3 ms |
1108 KB |
Output is correct |
34 |
Correct |
4 ms |
1108 KB |
Output is correct |
35 |
Correct |
2 ms |
972 KB |
Output is correct |
36 |
Correct |
1 ms |
980 KB |
Output is correct |
37 |
Correct |
3 ms |
1108 KB |
Output is correct |
38 |
Correct |
4 ms |
1044 KB |
Output is correct |
39 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
49 ms |
5272 KB |
Output is correct |
12 |
Correct |
30 ms |
3388 KB |
Output is correct |
13 |
Correct |
33 ms |
3772 KB |
Output is correct |
14 |
Correct |
48 ms |
5224 KB |
Output is correct |
15 |
Correct |
43 ms |
5268 KB |
Output is correct |
16 |
Correct |
38 ms |
5196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
49 ms |
5272 KB |
Output is correct |
12 |
Correct |
30 ms |
3388 KB |
Output is correct |
13 |
Correct |
33 ms |
3772 KB |
Output is correct |
14 |
Correct |
48 ms |
5224 KB |
Output is correct |
15 |
Correct |
43 ms |
5268 KB |
Output is correct |
16 |
Correct |
38 ms |
5196 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
2 ms |
980 KB |
Output is correct |
22 |
Correct |
60 ms |
5972 KB |
Output is correct |
23 |
Correct |
54 ms |
6032 KB |
Output is correct |
24 |
Correct |
39 ms |
4084 KB |
Output is correct |
25 |
Correct |
56 ms |
6304 KB |
Output is correct |
26 |
Correct |
48 ms |
6248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
49 ms |
5272 KB |
Output is correct |
12 |
Correct |
30 ms |
3388 KB |
Output is correct |
13 |
Correct |
33 ms |
3772 KB |
Output is correct |
14 |
Correct |
48 ms |
5224 KB |
Output is correct |
15 |
Correct |
43 ms |
5268 KB |
Output is correct |
16 |
Correct |
38 ms |
5196 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
2 ms |
980 KB |
Output is correct |
22 |
Correct |
60 ms |
5972 KB |
Output is correct |
23 |
Correct |
54 ms |
6032 KB |
Output is correct |
24 |
Correct |
39 ms |
4084 KB |
Output is correct |
25 |
Correct |
56 ms |
6304 KB |
Output is correct |
26 |
Correct |
48 ms |
6248 KB |
Output is correct |
27 |
Correct |
1 ms |
980 KB |
Output is correct |
28 |
Correct |
1 ms |
980 KB |
Output is correct |
29 |
Correct |
1 ms |
980 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
4 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
1 ms |
980 KB |
Output is correct |
34 |
Correct |
115 ms |
6316 KB |
Output is correct |
35 |
Correct |
94 ms |
6132 KB |
Output is correct |
36 |
Correct |
102 ms |
6312 KB |
Output is correct |
37 |
Correct |
83 ms |
6528 KB |
Output is correct |
38 |
Correct |
53 ms |
6348 KB |
Output is correct |
39 |
Correct |
31 ms |
3724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
49 ms |
5272 KB |
Output is correct |
12 |
Correct |
30 ms |
3388 KB |
Output is correct |
13 |
Correct |
33 ms |
3772 KB |
Output is correct |
14 |
Correct |
48 ms |
5224 KB |
Output is correct |
15 |
Correct |
43 ms |
5268 KB |
Output is correct |
16 |
Correct |
38 ms |
5196 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
852 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
2 ms |
980 KB |
Output is correct |
22 |
Correct |
60 ms |
5972 KB |
Output is correct |
23 |
Correct |
54 ms |
6032 KB |
Output is correct |
24 |
Correct |
39 ms |
4084 KB |
Output is correct |
25 |
Correct |
56 ms |
6304 KB |
Output is correct |
26 |
Correct |
48 ms |
6248 KB |
Output is correct |
27 |
Correct |
1 ms |
980 KB |
Output is correct |
28 |
Correct |
1 ms |
980 KB |
Output is correct |
29 |
Correct |
1 ms |
980 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
4 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
1 ms |
980 KB |
Output is correct |
34 |
Correct |
115 ms |
6316 KB |
Output is correct |
35 |
Correct |
94 ms |
6132 KB |
Output is correct |
36 |
Correct |
102 ms |
6312 KB |
Output is correct |
37 |
Correct |
83 ms |
6528 KB |
Output is correct |
38 |
Correct |
53 ms |
6348 KB |
Output is correct |
39 |
Correct |
31 ms |
3724 KB |
Output is correct |
40 |
Correct |
3 ms |
1108 KB |
Output is correct |
41 |
Correct |
4 ms |
1108 KB |
Output is correct |
42 |
Correct |
3 ms |
1100 KB |
Output is correct |
43 |
Correct |
3 ms |
1108 KB |
Output is correct |
44 |
Correct |
145 ms |
6600 KB |
Output is correct |
45 |
Correct |
128 ms |
6592 KB |
Output is correct |
46 |
Correct |
137 ms |
6624 KB |
Output is correct |
47 |
Correct |
136 ms |
6596 KB |
Output is correct |
48 |
Correct |
62 ms |
6552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
5 ms |
1108 KB |
Output is correct |
27 |
Correct |
5 ms |
1108 KB |
Output is correct |
28 |
Correct |
4 ms |
1188 KB |
Output is correct |
29 |
Correct |
4 ms |
1108 KB |
Output is correct |
30 |
Correct |
3 ms |
1108 KB |
Output is correct |
31 |
Correct |
4 ms |
1108 KB |
Output is correct |
32 |
Correct |
3 ms |
1112 KB |
Output is correct |
33 |
Correct |
3 ms |
1108 KB |
Output is correct |
34 |
Correct |
4 ms |
1108 KB |
Output is correct |
35 |
Correct |
2 ms |
972 KB |
Output is correct |
36 |
Correct |
1 ms |
980 KB |
Output is correct |
37 |
Correct |
3 ms |
1108 KB |
Output is correct |
38 |
Correct |
4 ms |
1044 KB |
Output is correct |
39 |
Correct |
2 ms |
980 KB |
Output is correct |
40 |
Correct |
1 ms |
980 KB |
Output is correct |
41 |
Correct |
1 ms |
980 KB |
Output is correct |
42 |
Correct |
1 ms |
852 KB |
Output is correct |
43 |
Correct |
1 ms |
980 KB |
Output is correct |
44 |
Correct |
1 ms |
980 KB |
Output is correct |
45 |
Correct |
1 ms |
980 KB |
Output is correct |
46 |
Correct |
1 ms |
980 KB |
Output is correct |
47 |
Correct |
1 ms |
852 KB |
Output is correct |
48 |
Correct |
1 ms |
980 KB |
Output is correct |
49 |
Correct |
1 ms |
980 KB |
Output is correct |
50 |
Correct |
49 ms |
5272 KB |
Output is correct |
51 |
Correct |
30 ms |
3388 KB |
Output is correct |
52 |
Correct |
33 ms |
3772 KB |
Output is correct |
53 |
Correct |
48 ms |
5224 KB |
Output is correct |
54 |
Correct |
43 ms |
5268 KB |
Output is correct |
55 |
Correct |
38 ms |
5196 KB |
Output is correct |
56 |
Correct |
1 ms |
852 KB |
Output is correct |
57 |
Correct |
1 ms |
852 KB |
Output is correct |
58 |
Correct |
1 ms |
980 KB |
Output is correct |
59 |
Correct |
1 ms |
980 KB |
Output is correct |
60 |
Correct |
2 ms |
980 KB |
Output is correct |
61 |
Correct |
60 ms |
5972 KB |
Output is correct |
62 |
Correct |
54 ms |
6032 KB |
Output is correct |
63 |
Correct |
39 ms |
4084 KB |
Output is correct |
64 |
Correct |
56 ms |
6304 KB |
Output is correct |
65 |
Correct |
48 ms |
6248 KB |
Output is correct |
66 |
Correct |
1 ms |
980 KB |
Output is correct |
67 |
Correct |
1 ms |
980 KB |
Output is correct |
68 |
Correct |
1 ms |
980 KB |
Output is correct |
69 |
Correct |
1 ms |
980 KB |
Output is correct |
70 |
Correct |
4 ms |
1108 KB |
Output is correct |
71 |
Correct |
1 ms |
972 KB |
Output is correct |
72 |
Correct |
1 ms |
980 KB |
Output is correct |
73 |
Correct |
115 ms |
6316 KB |
Output is correct |
74 |
Correct |
94 ms |
6132 KB |
Output is correct |
75 |
Correct |
102 ms |
6312 KB |
Output is correct |
76 |
Correct |
83 ms |
6528 KB |
Output is correct |
77 |
Correct |
53 ms |
6348 KB |
Output is correct |
78 |
Correct |
31 ms |
3724 KB |
Output is correct |
79 |
Correct |
3 ms |
1108 KB |
Output is correct |
80 |
Correct |
4 ms |
1108 KB |
Output is correct |
81 |
Correct |
3 ms |
1100 KB |
Output is correct |
82 |
Correct |
3 ms |
1108 KB |
Output is correct |
83 |
Correct |
145 ms |
6600 KB |
Output is correct |
84 |
Correct |
128 ms |
6592 KB |
Output is correct |
85 |
Correct |
137 ms |
6624 KB |
Output is correct |
86 |
Correct |
136 ms |
6596 KB |
Output is correct |
87 |
Correct |
62 ms |
6552 KB |
Output is correct |
88 |
Correct |
206 ms |
8320 KB |
Output is correct |
89 |
Correct |
186 ms |
8300 KB |
Output is correct |
90 |
Correct |
206 ms |
10168 KB |
Output is correct |
91 |
Correct |
165 ms |
7660 KB |
Output is correct |
92 |
Correct |
164 ms |
7140 KB |
Output is correct |
93 |
Correct |
176 ms |
8940 KB |
Output is correct |
94 |
Correct |
162 ms |
8504 KB |
Output is correct |
95 |
Correct |
93 ms |
8984 KB |
Output is correct |
96 |
Correct |
126 ms |
9960 KB |
Output is correct |
97 |
Correct |
74 ms |
7812 KB |
Output is correct |
98 |
Correct |
91 ms |
8172 KB |
Output is correct |
99 |
Correct |
132 ms |
8132 KB |
Output is correct |