#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) {
oaox[0][i] = oaox[i][0] = 0;
oaoy[0][i] = oaoy[i][0] = 1e18;
oaoz[0][i] = oaoz[i][0] = 1e18;
}
for(auto &i:v) {
cin >> i.x >> i.y >> i.z;
chmax(oaoy[i.y][i.z + 1], i.x);
chmax(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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
346 ms |
400 KB |
Output is correct |
27 |
Correct |
274 ms |
412 KB |
Output is correct |
28 |
Correct |
244 ms |
404 KB |
Output is correct |
29 |
Correct |
201 ms |
404 KB |
Output is correct |
30 |
Correct |
111 ms |
376 KB |
Output is correct |
31 |
Correct |
301 ms |
400 KB |
Output is correct |
32 |
Correct |
319 ms |
408 KB |
Output is correct |
33 |
Correct |
215 ms |
400 KB |
Output is correct |
34 |
Correct |
103 ms |
404 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
348 KB |
Output is correct |
37 |
Correct |
114 ms |
408 KB |
Output is correct |
38 |
Correct |
112 ms |
404 KB |
Output is correct |
39 |
Correct |
62 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
273 ms |
381604 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
273 ms |
381604 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
273 ms |
381604 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Incorrect |
273 ms |
381604 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
346 ms |
400 KB |
Output is correct |
27 |
Correct |
274 ms |
412 KB |
Output is correct |
28 |
Correct |
244 ms |
404 KB |
Output is correct |
29 |
Correct |
201 ms |
404 KB |
Output is correct |
30 |
Correct |
111 ms |
376 KB |
Output is correct |
31 |
Correct |
301 ms |
400 KB |
Output is correct |
32 |
Correct |
319 ms |
408 KB |
Output is correct |
33 |
Correct |
215 ms |
400 KB |
Output is correct |
34 |
Correct |
103 ms |
404 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
348 KB |
Output is correct |
37 |
Correct |
114 ms |
408 KB |
Output is correct |
38 |
Correct |
112 ms |
404 KB |
Output is correct |
39 |
Correct |
62 ms |
360 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Incorrect |
273 ms |
381604 KB |
Output isn't correct |
51 |
Halted |
0 ms |
0 KB |
- |