#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 = 4005;
int n;
vector<trip> vec;
vi ys, zs;
int mxZPref[MN], mxYPref[MN], mxZ[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];
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;
FR(k, yPos) mz = max(mz, mxZPref[k]);
if(mz > z) mxZ[yPos] = max(mxZ[yPos], mz);
mxYPref[zPos] = max(mxYPref[zPos], y);
int mxY = 0;
FR(k, zPos) mxY = max(mxY, mxYPref[k]);
if(mxY > y){
int yp1 = lbv(ys, mxY);
mxZ[yp1] = max(mxZ[yp1], z);
}
mxZPref[yPos] = max(mxZPref[yPos], z);
}
prvX = vec[i][0];
lst = i;
}
auto [x, y, z] = vec[i];
int yPos = lbv(ys, y);
int mxSum = 0;
FOR(j, yPos+1, n) mxSum = max(mxSum, (ys[j] + mxZ[j]) * (mxZ[j] > z));
if(mxSum) ans = max(ans, mxSum + x);
}
if(ans == -1) vi vec(1e7, 1234);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
39352 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
19 ms |
39392 KB |
Output is correct |
6 |
Correct |
19 ms |
39452 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
20 ms |
39464 KB |
Output is correct |
9 |
Correct |
21 ms |
39436 KB |
Output is correct |
10 |
Correct |
23 ms |
39416 KB |
Output is correct |
11 |
Correct |
22 ms |
39360 KB |
Output is correct |
12 |
Correct |
19 ms |
39380 KB |
Output is correct |
13 |
Correct |
19 ms |
39364 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
19 ms |
39408 KB |
Output is correct |
21 |
Correct |
26 ms |
39448 KB |
Output is correct |
22 |
Correct |
21 ms |
39484 KB |
Output is correct |
23 |
Correct |
19 ms |
39492 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
39352 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
19 ms |
39392 KB |
Output is correct |
6 |
Correct |
19 ms |
39452 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
20 ms |
39464 KB |
Output is correct |
9 |
Correct |
21 ms |
39436 KB |
Output is correct |
10 |
Correct |
23 ms |
39416 KB |
Output is correct |
11 |
Correct |
22 ms |
39360 KB |
Output is correct |
12 |
Correct |
19 ms |
39380 KB |
Output is correct |
13 |
Correct |
19 ms |
39364 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
19 ms |
39408 KB |
Output is correct |
21 |
Correct |
26 ms |
39448 KB |
Output is correct |
22 |
Correct |
21 ms |
39484 KB |
Output is correct |
23 |
Correct |
19 ms |
39492 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
34 ms |
468 KB |
Output is correct |
27 |
Correct |
25 ms |
468 KB |
Output is correct |
28 |
Correct |
19 ms |
552 KB |
Output is correct |
29 |
Correct |
33 ms |
39624 KB |
Output is correct |
30 |
Correct |
9 ms |
476 KB |
Output is correct |
31 |
Correct |
10 ms |
480 KB |
Output is correct |
32 |
Correct |
25 ms |
39580 KB |
Output is correct |
33 |
Correct |
25 ms |
39644 KB |
Output is correct |
34 |
Correct |
52 ms |
39628 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
10 ms |
468 KB |
Output is correct |
38 |
Correct |
11 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
19 ms |
39428 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
20 ms |
39412 KB |
Output is correct |
6 |
Correct |
19 ms |
39456 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
19 ms |
39460 KB |
Output is correct |
9 |
Correct |
20 ms |
39436 KB |
Output is correct |
10 |
Correct |
20 ms |
39444 KB |
Output is correct |
11 |
Correct |
47 ms |
4732 KB |
Output is correct |
12 |
Correct |
32 ms |
2780 KB |
Output is correct |
13 |
Correct |
35 ms |
3400 KB |
Output is correct |
14 |
Correct |
67 ms |
43924 KB |
Output is correct |
15 |
Correct |
66 ms |
43984 KB |
Output is correct |
16 |
Correct |
61 ms |
43976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
19 ms |
39428 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
20 ms |
39412 KB |
Output is correct |
6 |
Correct |
19 ms |
39456 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
19 ms |
39460 KB |
Output is correct |
9 |
Correct |
20 ms |
39436 KB |
Output is correct |
10 |
Correct |
20 ms |
39444 KB |
Output is correct |
11 |
Correct |
47 ms |
4732 KB |
Output is correct |
12 |
Correct |
32 ms |
2780 KB |
Output is correct |
13 |
Correct |
35 ms |
3400 KB |
Output is correct |
14 |
Correct |
67 ms |
43924 KB |
Output is correct |
15 |
Correct |
66 ms |
43984 KB |
Output is correct |
16 |
Correct |
61 ms |
43976 KB |
Output is correct |
17 |
Correct |
18 ms |
39424 KB |
Output is correct |
18 |
Correct |
23 ms |
39388 KB |
Output is correct |
19 |
Correct |
19 ms |
39372 KB |
Output is correct |
20 |
Correct |
22 ms |
39556 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
63 ms |
5000 KB |
Output is correct |
23 |
Correct |
55 ms |
5008 KB |
Output is correct |
24 |
Correct |
48 ms |
3016 KB |
Output is correct |
25 |
Correct |
77 ms |
43936 KB |
Output is correct |
26 |
Correct |
64 ms |
43988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
19 ms |
39428 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
20 ms |
39412 KB |
Output is correct |
6 |
Correct |
19 ms |
39456 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
19 ms |
39460 KB |
Output is correct |
9 |
Correct |
20 ms |
39436 KB |
Output is correct |
10 |
Correct |
20 ms |
39444 KB |
Output is correct |
11 |
Correct |
47 ms |
4732 KB |
Output is correct |
12 |
Correct |
32 ms |
2780 KB |
Output is correct |
13 |
Correct |
35 ms |
3400 KB |
Output is correct |
14 |
Correct |
67 ms |
43924 KB |
Output is correct |
15 |
Correct |
66 ms |
43984 KB |
Output is correct |
16 |
Correct |
61 ms |
43976 KB |
Output is correct |
17 |
Correct |
18 ms |
39424 KB |
Output is correct |
18 |
Correct |
23 ms |
39388 KB |
Output is correct |
19 |
Correct |
19 ms |
39372 KB |
Output is correct |
20 |
Correct |
22 ms |
39556 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
63 ms |
5000 KB |
Output is correct |
23 |
Correct |
55 ms |
5008 KB |
Output is correct |
24 |
Correct |
48 ms |
3016 KB |
Output is correct |
25 |
Correct |
77 ms |
43936 KB |
Output is correct |
26 |
Correct |
64 ms |
43988 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
23 ms |
39636 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
150 ms |
5012 KB |
Output is correct |
35 |
Correct |
131 ms |
4952 KB |
Output is correct |
36 |
Correct |
141 ms |
4996 KB |
Output is correct |
37 |
Correct |
141 ms |
43896 KB |
Output is correct |
38 |
Correct |
69 ms |
43884 KB |
Output is correct |
39 |
Correct |
65 ms |
41760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
19 ms |
39428 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
20 ms |
39412 KB |
Output is correct |
6 |
Correct |
19 ms |
39456 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
19 ms |
39460 KB |
Output is correct |
9 |
Correct |
20 ms |
39436 KB |
Output is correct |
10 |
Correct |
20 ms |
39444 KB |
Output is correct |
11 |
Correct |
47 ms |
4732 KB |
Output is correct |
12 |
Correct |
32 ms |
2780 KB |
Output is correct |
13 |
Correct |
35 ms |
3400 KB |
Output is correct |
14 |
Correct |
67 ms |
43924 KB |
Output is correct |
15 |
Correct |
66 ms |
43984 KB |
Output is correct |
16 |
Correct |
61 ms |
43976 KB |
Output is correct |
17 |
Correct |
18 ms |
39424 KB |
Output is correct |
18 |
Correct |
23 ms |
39388 KB |
Output is correct |
19 |
Correct |
19 ms |
39372 KB |
Output is correct |
20 |
Correct |
22 ms |
39556 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
63 ms |
5000 KB |
Output is correct |
23 |
Correct |
55 ms |
5008 KB |
Output is correct |
24 |
Correct |
48 ms |
3016 KB |
Output is correct |
25 |
Correct |
77 ms |
43936 KB |
Output is correct |
26 |
Correct |
64 ms |
43988 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
23 ms |
39636 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
150 ms |
5012 KB |
Output is correct |
35 |
Correct |
131 ms |
4952 KB |
Output is correct |
36 |
Correct |
141 ms |
4996 KB |
Output is correct |
37 |
Correct |
141 ms |
43896 KB |
Output is correct |
38 |
Correct |
69 ms |
43884 KB |
Output is correct |
39 |
Correct |
65 ms |
41760 KB |
Output is correct |
40 |
Correct |
9 ms |
468 KB |
Output is correct |
41 |
Correct |
9 ms |
468 KB |
Output is correct |
42 |
Correct |
10 ms |
468 KB |
Output is correct |
43 |
Correct |
12 ms |
468 KB |
Output is correct |
44 |
Correct |
1064 ms |
4984 KB |
Output is correct |
45 |
Correct |
1018 ms |
4952 KB |
Output is correct |
46 |
Correct |
1057 ms |
4960 KB |
Output is correct |
47 |
Correct |
1133 ms |
44136 KB |
Output is correct |
48 |
Correct |
92 ms |
44016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
39352 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
19 ms |
39392 KB |
Output is correct |
6 |
Correct |
19 ms |
39452 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
20 ms |
39464 KB |
Output is correct |
9 |
Correct |
21 ms |
39436 KB |
Output is correct |
10 |
Correct |
23 ms |
39416 KB |
Output is correct |
11 |
Correct |
22 ms |
39360 KB |
Output is correct |
12 |
Correct |
19 ms |
39380 KB |
Output is correct |
13 |
Correct |
19 ms |
39364 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
22 ms |
39380 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
19 ms |
39408 KB |
Output is correct |
21 |
Correct |
26 ms |
39448 KB |
Output is correct |
22 |
Correct |
21 ms |
39484 KB |
Output is correct |
23 |
Correct |
19 ms |
39492 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
34 ms |
468 KB |
Output is correct |
27 |
Correct |
25 ms |
468 KB |
Output is correct |
28 |
Correct |
19 ms |
552 KB |
Output is correct |
29 |
Correct |
33 ms |
39624 KB |
Output is correct |
30 |
Correct |
9 ms |
476 KB |
Output is correct |
31 |
Correct |
10 ms |
480 KB |
Output is correct |
32 |
Correct |
25 ms |
39580 KB |
Output is correct |
33 |
Correct |
25 ms |
39644 KB |
Output is correct |
34 |
Correct |
52 ms |
39628 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
10 ms |
468 KB |
Output is correct |
38 |
Correct |
11 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
19 ms |
39428 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
20 ms |
39412 KB |
Output is correct |
45 |
Correct |
19 ms |
39456 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
19 ms |
39460 KB |
Output is correct |
48 |
Correct |
20 ms |
39436 KB |
Output is correct |
49 |
Correct |
20 ms |
39444 KB |
Output is correct |
50 |
Correct |
47 ms |
4732 KB |
Output is correct |
51 |
Correct |
32 ms |
2780 KB |
Output is correct |
52 |
Correct |
35 ms |
3400 KB |
Output is correct |
53 |
Correct |
67 ms |
43924 KB |
Output is correct |
54 |
Correct |
66 ms |
43984 KB |
Output is correct |
55 |
Correct |
61 ms |
43976 KB |
Output is correct |
56 |
Correct |
18 ms |
39424 KB |
Output is correct |
57 |
Correct |
23 ms |
39388 KB |
Output is correct |
58 |
Correct |
19 ms |
39372 KB |
Output is correct |
59 |
Correct |
22 ms |
39556 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
63 ms |
5000 KB |
Output is correct |
62 |
Correct |
55 ms |
5008 KB |
Output is correct |
63 |
Correct |
48 ms |
3016 KB |
Output is correct |
64 |
Correct |
77 ms |
43936 KB |
Output is correct |
65 |
Correct |
64 ms |
43988 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
23 ms |
39636 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
150 ms |
5012 KB |
Output is correct |
74 |
Correct |
131 ms |
4952 KB |
Output is correct |
75 |
Correct |
141 ms |
4996 KB |
Output is correct |
76 |
Correct |
141 ms |
43896 KB |
Output is correct |
77 |
Correct |
69 ms |
43884 KB |
Output is correct |
78 |
Correct |
65 ms |
41760 KB |
Output is correct |
79 |
Correct |
9 ms |
468 KB |
Output is correct |
80 |
Correct |
9 ms |
468 KB |
Output is correct |
81 |
Correct |
10 ms |
468 KB |
Output is correct |
82 |
Correct |
12 ms |
468 KB |
Output is correct |
83 |
Correct |
1064 ms |
4984 KB |
Output is correct |
84 |
Correct |
1018 ms |
4952 KB |
Output is correct |
85 |
Correct |
1057 ms |
4960 KB |
Output is correct |
86 |
Correct |
1133 ms |
44136 KB |
Output is correct |
87 |
Correct |
92 ms |
44016 KB |
Output is correct |
88 |
Runtime error |
85 ms |
9572 KB |
Execution killed with signal 11 |
89 |
Halted |
0 ms |
0 KB |
- |