#include <bits/stdc++.h>
#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 F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
inline void chmax(int &l, const int &r) {
l = max(l, r);
}
inline void chmin(int &l, const int &r) {
l = min(l, r);
}
struct Owo {
int x, y, z;
};
void solve1(int n) {
vector<Owo> v(n);
for(auto &i:v) {
cin >> i.x >> i.y >> i.z;
}
sort(all(v), [](const auto &a, const auto &b) {
return a.z < b.z;
});
int ans = -1;
For(r, 2, n - 1) {
sort(v.begin(), v.begin() + r, [](const auto &a, const auto &b) {
return a.y < b.y;
});
int mxx = -1e18;
int tmp = -1e18;
For(m, 0, r - 1) {
if(v[m].z == v[r].z) continue;
if(v[m].y > v[r].y && mxx > max(v[m].x, v[r].x)) {
ans = max(ans, v[m].y + v[r].z + mxx);
}
tmp = max(tmp, v[m].x);
if(v[m + 1].y != v[m].y) mxx = tmp;
}
}
cout << ans << "\n";
}
const int MAX = 4010;
int oaox[MAX][MAX];
int oaoy[MAX][MAX];
int oaoz[MAX][MAX];
void solve2(int n) {
vector<Owo> v(n);
For(i, 0, MAX - 1) For(j, 0, MAX - 1) {
oaox[i][j] = 0;
oaoz[i][j] = oaoy[i][j] = 1e18;
}
for(auto &i:v) {
cin >> i.x >> i.y >> i.z;
chmin(oaoy[i.y][i.z + 1], i.x);
chmin(oaoz[i.y + 1][i.z], i.x);
chmax(oaox[i.y][i.z], i.x);
}
int ans = -1;
For(i, 1, MAX - 1) For(j, 1, MAX - 1) {
chmax(oaox[i][j], max(oaox[i - 1][j], oaox[i][j - 1]));
chmin(oaoy[i][j], oaoy[i][j - 1]);
chmin(oaoz[i][j], oaoz[i - 1][j]);
if(oaox[i - 1][j - 1] > max(oaoy[i][j], oaoz[i][j])) {
chmax(ans, oaox[i - 1][j - 1] + i + j);
}
}
cout << ans << "\n";
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// OAO
int n; cin >> n;
if(n <= 4000) solve1(n);
else solve2(n);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
321 ms |
404 KB |
Output is correct |
27 |
Correct |
290 ms |
404 KB |
Output is correct |
28 |
Correct |
245 ms |
400 KB |
Output is correct |
29 |
Correct |
187 ms |
412 KB |
Output is correct |
30 |
Correct |
108 ms |
340 KB |
Output is correct |
31 |
Correct |
299 ms |
408 KB |
Output is correct |
32 |
Correct |
309 ms |
404 KB |
Output is correct |
33 |
Correct |
204 ms |
340 KB |
Output is correct |
34 |
Correct |
97 ms |
404 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
6 ms |
340 KB |
Output is correct |
37 |
Correct |
110 ms |
340 KB |
Output is correct |
38 |
Correct |
107 ms |
340 KB |
Output is correct |
39 |
Correct |
58 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 |
0 ms |
224 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
218 ms |
381384 KB |
Output is correct |
12 |
Correct |
218 ms |
380244 KB |
Output is correct |
13 |
Correct |
215 ms |
380800 KB |
Output is correct |
14 |
Correct |
219 ms |
381340 KB |
Output is correct |
15 |
Correct |
221 ms |
381388 KB |
Output is correct |
16 |
Correct |
227 ms |
381368 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 |
0 ms |
224 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
218 ms |
381384 KB |
Output is correct |
12 |
Correct |
218 ms |
380244 KB |
Output is correct |
13 |
Correct |
215 ms |
380800 KB |
Output is correct |
14 |
Correct |
219 ms |
381340 KB |
Output is correct |
15 |
Correct |
221 ms |
381388 KB |
Output is correct |
16 |
Correct |
227 ms |
381368 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
59 ms |
364 KB |
Output is correct |
22 |
Correct |
221 ms |
381388 KB |
Output is correct |
23 |
Correct |
220 ms |
381324 KB |
Output is correct |
24 |
Correct |
220 ms |
380364 KB |
Output is correct |
25 |
Correct |
222 ms |
381388 KB |
Output is correct |
26 |
Correct |
218 ms |
381436 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 |
0 ms |
224 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
218 ms |
381384 KB |
Output is correct |
12 |
Correct |
218 ms |
380244 KB |
Output is correct |
13 |
Correct |
215 ms |
380800 KB |
Output is correct |
14 |
Correct |
219 ms |
381340 KB |
Output is correct |
15 |
Correct |
221 ms |
381388 KB |
Output is correct |
16 |
Correct |
227 ms |
381368 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
59 ms |
364 KB |
Output is correct |
22 |
Correct |
221 ms |
381388 KB |
Output is correct |
23 |
Correct |
220 ms |
381324 KB |
Output is correct |
24 |
Correct |
220 ms |
380364 KB |
Output is correct |
25 |
Correct |
222 ms |
381388 KB |
Output is correct |
26 |
Correct |
218 ms |
381436 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
320 ms |
460 KB |
Output is correct |
32 |
Correct |
6 ms |
352 KB |
Output is correct |
33 |
Correct |
5 ms |
340 KB |
Output is correct |
34 |
Correct |
228 ms |
381260 KB |
Output is correct |
35 |
Correct |
234 ms |
381012 KB |
Output is correct |
36 |
Correct |
234 ms |
381420 KB |
Output is correct |
37 |
Correct |
228 ms |
381372 KB |
Output is correct |
38 |
Correct |
245 ms |
381272 KB |
Output is correct |
39 |
Correct |
213 ms |
379964 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 |
0 ms |
224 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
218 ms |
381384 KB |
Output is correct |
12 |
Correct |
218 ms |
380244 KB |
Output is correct |
13 |
Correct |
215 ms |
380800 KB |
Output is correct |
14 |
Correct |
219 ms |
381340 KB |
Output is correct |
15 |
Correct |
221 ms |
381388 KB |
Output is correct |
16 |
Correct |
227 ms |
381368 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
59 ms |
364 KB |
Output is correct |
22 |
Correct |
221 ms |
381388 KB |
Output is correct |
23 |
Correct |
220 ms |
381324 KB |
Output is correct |
24 |
Correct |
220 ms |
380364 KB |
Output is correct |
25 |
Correct |
222 ms |
381388 KB |
Output is correct |
26 |
Correct |
218 ms |
381436 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
320 ms |
460 KB |
Output is correct |
32 |
Correct |
6 ms |
352 KB |
Output is correct |
33 |
Correct |
5 ms |
340 KB |
Output is correct |
34 |
Correct |
228 ms |
381260 KB |
Output is correct |
35 |
Correct |
234 ms |
381012 KB |
Output is correct |
36 |
Correct |
234 ms |
381420 KB |
Output is correct |
37 |
Correct |
228 ms |
381372 KB |
Output is correct |
38 |
Correct |
245 ms |
381272 KB |
Output is correct |
39 |
Correct |
213 ms |
379964 KB |
Output is correct |
40 |
Correct |
109 ms |
340 KB |
Output is correct |
41 |
Correct |
291 ms |
468 KB |
Output is correct |
42 |
Correct |
128 ms |
468 KB |
Output is correct |
43 |
Correct |
116 ms |
468 KB |
Output is correct |
44 |
Correct |
256 ms |
381496 KB |
Output is correct |
45 |
Correct |
251 ms |
381548 KB |
Output is correct |
46 |
Correct |
255 ms |
381516 KB |
Output is correct |
47 |
Correct |
249 ms |
381468 KB |
Output is correct |
48 |
Correct |
235 ms |
381564 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
321 ms |
404 KB |
Output is correct |
27 |
Correct |
290 ms |
404 KB |
Output is correct |
28 |
Correct |
245 ms |
400 KB |
Output is correct |
29 |
Correct |
187 ms |
412 KB |
Output is correct |
30 |
Correct |
108 ms |
340 KB |
Output is correct |
31 |
Correct |
299 ms |
408 KB |
Output is correct |
32 |
Correct |
309 ms |
404 KB |
Output is correct |
33 |
Correct |
204 ms |
340 KB |
Output is correct |
34 |
Correct |
97 ms |
404 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
6 ms |
340 KB |
Output is correct |
37 |
Correct |
110 ms |
340 KB |
Output is correct |
38 |
Correct |
107 ms |
340 KB |
Output is correct |
39 |
Correct |
58 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 |
0 ms |
224 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
218 ms |
381384 KB |
Output is correct |
51 |
Correct |
218 ms |
380244 KB |
Output is correct |
52 |
Correct |
215 ms |
380800 KB |
Output is correct |
53 |
Correct |
219 ms |
381340 KB |
Output is correct |
54 |
Correct |
221 ms |
381388 KB |
Output is correct |
55 |
Correct |
227 ms |
381368 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
59 ms |
364 KB |
Output is correct |
61 |
Correct |
221 ms |
381388 KB |
Output is correct |
62 |
Correct |
220 ms |
381324 KB |
Output is correct |
63 |
Correct |
220 ms |
380364 KB |
Output is correct |
64 |
Correct |
222 ms |
381388 KB |
Output is correct |
65 |
Correct |
218 ms |
381436 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
2 ms |
212 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
212 KB |
Output is correct |
70 |
Correct |
320 ms |
460 KB |
Output is correct |
71 |
Correct |
6 ms |
352 KB |
Output is correct |
72 |
Correct |
5 ms |
340 KB |
Output is correct |
73 |
Correct |
228 ms |
381260 KB |
Output is correct |
74 |
Correct |
234 ms |
381012 KB |
Output is correct |
75 |
Correct |
234 ms |
381420 KB |
Output is correct |
76 |
Correct |
228 ms |
381372 KB |
Output is correct |
77 |
Correct |
245 ms |
381272 KB |
Output is correct |
78 |
Correct |
213 ms |
379964 KB |
Output is correct |
79 |
Correct |
109 ms |
340 KB |
Output is correct |
80 |
Correct |
291 ms |
468 KB |
Output is correct |
81 |
Correct |
128 ms |
468 KB |
Output is correct |
82 |
Correct |
116 ms |
468 KB |
Output is correct |
83 |
Correct |
256 ms |
381496 KB |
Output is correct |
84 |
Correct |
251 ms |
381548 KB |
Output is correct |
85 |
Correct |
255 ms |
381516 KB |
Output is correct |
86 |
Correct |
249 ms |
381468 KB |
Output is correct |
87 |
Correct |
235 ms |
381564 KB |
Output is correct |
88 |
Runtime error |
473 ms |
773232 KB |
Execution killed with signal 11 |
89 |
Halted |
0 ms |
0 KB |
- |