#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
const int N = 2e5 + 69;
const int A = 4010;
const int inf = 1e9;
int n, a[N], b[N], c[N], d[A][A];
int gmx[A][A], gmn[A][A], mn[A][A];
map<int, int> ca, cb, cc;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
vector<int> x, y, z;
for (int i = 1;i <= n;i++) {
cin >> a[i] >> b[i] >> c[i];
x.push_back(a[i]);
y.push_back(b[i]);
z.push_back(c[i]);
}
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
sort(y.begin(), y.end());
y.erase(unique(y.begin(), y.end()), y.end());
sort(z.begin(), z.end());
z.erase(unique(z.begin(), z.end()), z.end());
for (int i = 1;i <= n;i++) {
auto u = lower_bound(x.begin(), x.end(), a[i]) - x.begin() + 1;
ca[u] = a[i];
a[i] = u;
u = lower_bound(y.begin(), y.end(), b[i]) - y.begin() + 1;
cb[u] = b[i];
b[i] = u;
u = lower_bound(z.begin(), z.end(), c[i]) - z.begin() + 1;
cc[u] = c[i];
c[i] = u;
}
for (int i = 0;i < A;i++) {
for (int j = 0;j < A;j++) {
gmn[i][j] = inf;
gmx[i][j] = -inf;
d[i][j] = -inf;
mn[i][j] = inf;
}
}
for (int i = 1;i <= n;i++) {
gmx[a[i]][b[i]] = max(c[i], gmx[a[i]][b[i]]);
gmn[a[i]][b[i]] = min(c[i], gmn[a[i]][b[i]]);
}
for (int i = 1;i < A;i++) {
for (int j = 1;j < A;j++) {
d[i][j] = max({d[i][j - 1], d[i - 1][j], gmx[i][j]});
mn[i][j] = min(mn[i][j - 1], gmn[i][j]);
}
}
int ans = -1;
for (int i = 1;i <= n;i++) {
for (int j = a[i] + 1;j < (n > 4000 ? 1000 : A);j++) {
if (mn[j][b[i] - 1] < d[j - 1][b[i] - 1] && d[j - 1][b[i] - 1] > c[i]) {
ans = max(ans, cb[b[i]] + ca[j] + cc[d[j - 1][b[i] - 1]]);
}
}
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
253008 KB |
Output is correct |
2 |
Correct |
128 ms |
253232 KB |
Output is correct |
3 |
Correct |
126 ms |
253008 KB |
Output is correct |
4 |
Correct |
124 ms |
252904 KB |
Output is correct |
5 |
Correct |
161 ms |
253264 KB |
Output is correct |
6 |
Correct |
123 ms |
253180 KB |
Output is correct |
7 |
Correct |
156 ms |
253012 KB |
Output is correct |
8 |
Correct |
126 ms |
253004 KB |
Output is correct |
9 |
Correct |
150 ms |
252844 KB |
Output is correct |
10 |
Correct |
114 ms |
252872 KB |
Output is correct |
11 |
Correct |
110 ms |
253012 KB |
Output is correct |
12 |
Correct |
129 ms |
253012 KB |
Output is correct |
13 |
Correct |
131 ms |
253336 KB |
Output is correct |
14 |
Correct |
163 ms |
253072 KB |
Output is correct |
15 |
Correct |
150 ms |
252884 KB |
Output is correct |
16 |
Correct |
168 ms |
253052 KB |
Output is correct |
17 |
Correct |
143 ms |
253012 KB |
Output is correct |
18 |
Correct |
167 ms |
253024 KB |
Output is correct |
19 |
Correct |
142 ms |
253264 KB |
Output is correct |
20 |
Correct |
140 ms |
253016 KB |
Output is correct |
21 |
Correct |
131 ms |
253044 KB |
Output is correct |
22 |
Correct |
135 ms |
253064 KB |
Output is correct |
23 |
Correct |
138 ms |
253144 KB |
Output is correct |
24 |
Correct |
139 ms |
253044 KB |
Output is correct |
25 |
Correct |
142 ms |
252888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
253008 KB |
Output is correct |
2 |
Correct |
128 ms |
253232 KB |
Output is correct |
3 |
Correct |
126 ms |
253008 KB |
Output is correct |
4 |
Correct |
124 ms |
252904 KB |
Output is correct |
5 |
Correct |
161 ms |
253264 KB |
Output is correct |
6 |
Correct |
123 ms |
253180 KB |
Output is correct |
7 |
Correct |
156 ms |
253012 KB |
Output is correct |
8 |
Correct |
126 ms |
253004 KB |
Output is correct |
9 |
Correct |
150 ms |
252844 KB |
Output is correct |
10 |
Correct |
114 ms |
252872 KB |
Output is correct |
11 |
Correct |
110 ms |
253012 KB |
Output is correct |
12 |
Correct |
129 ms |
253012 KB |
Output is correct |
13 |
Correct |
131 ms |
253336 KB |
Output is correct |
14 |
Correct |
163 ms |
253072 KB |
Output is correct |
15 |
Correct |
150 ms |
252884 KB |
Output is correct |
16 |
Correct |
168 ms |
253052 KB |
Output is correct |
17 |
Correct |
143 ms |
253012 KB |
Output is correct |
18 |
Correct |
167 ms |
253024 KB |
Output is correct |
19 |
Correct |
142 ms |
253264 KB |
Output is correct |
20 |
Correct |
140 ms |
253016 KB |
Output is correct |
21 |
Correct |
131 ms |
253044 KB |
Output is correct |
22 |
Correct |
135 ms |
253064 KB |
Output is correct |
23 |
Correct |
138 ms |
253144 KB |
Output is correct |
24 |
Correct |
139 ms |
253044 KB |
Output is correct |
25 |
Correct |
142 ms |
252888 KB |
Output is correct |
26 |
Correct |
985 ms |
253744 KB |
Output is correct |
27 |
Correct |
718 ms |
253524 KB |
Output is correct |
28 |
Correct |
611 ms |
253500 KB |
Output is correct |
29 |
Correct |
459 ms |
253328 KB |
Output is correct |
30 |
Correct |
387 ms |
253268 KB |
Output is correct |
31 |
Correct |
593 ms |
253228 KB |
Output is correct |
32 |
Correct |
296 ms |
253104 KB |
Output is correct |
33 |
Correct |
249 ms |
253208 KB |
Output is correct |
34 |
Correct |
287 ms |
253528 KB |
Output is correct |
35 |
Correct |
137 ms |
253016 KB |
Output is correct |
36 |
Correct |
137 ms |
253068 KB |
Output is correct |
37 |
Correct |
260 ms |
253264 KB |
Output is correct |
38 |
Correct |
195 ms |
253012 KB |
Output is correct |
39 |
Correct |
170 ms |
253264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
253008 KB |
Output is correct |
2 |
Correct |
110 ms |
252924 KB |
Output is correct |
3 |
Correct |
113 ms |
252864 KB |
Output is correct |
4 |
Correct |
112 ms |
252968 KB |
Output is correct |
5 |
Correct |
110 ms |
253008 KB |
Output is correct |
6 |
Correct |
111 ms |
253020 KB |
Output is correct |
7 |
Correct |
152 ms |
252924 KB |
Output is correct |
8 |
Correct |
112 ms |
253048 KB |
Output is correct |
9 |
Correct |
111 ms |
252756 KB |
Output is correct |
10 |
Correct |
110 ms |
252948 KB |
Output is correct |
11 |
Correct |
441 ms |
255960 KB |
Output is correct |
12 |
Correct |
357 ms |
254920 KB |
Output is correct |
13 |
Correct |
410 ms |
255480 KB |
Output is correct |
14 |
Correct |
461 ms |
256052 KB |
Output is correct |
15 |
Correct |
487 ms |
255984 KB |
Output is correct |
16 |
Correct |
634 ms |
255932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
253008 KB |
Output is correct |
2 |
Correct |
110 ms |
252924 KB |
Output is correct |
3 |
Correct |
113 ms |
252864 KB |
Output is correct |
4 |
Correct |
112 ms |
252968 KB |
Output is correct |
5 |
Correct |
110 ms |
253008 KB |
Output is correct |
6 |
Correct |
111 ms |
253020 KB |
Output is correct |
7 |
Correct |
152 ms |
252924 KB |
Output is correct |
8 |
Correct |
112 ms |
253048 KB |
Output is correct |
9 |
Correct |
111 ms |
252756 KB |
Output is correct |
10 |
Correct |
110 ms |
252948 KB |
Output is correct |
11 |
Correct |
441 ms |
255960 KB |
Output is correct |
12 |
Correct |
357 ms |
254920 KB |
Output is correct |
13 |
Correct |
410 ms |
255480 KB |
Output is correct |
14 |
Correct |
461 ms |
256052 KB |
Output is correct |
15 |
Correct |
487 ms |
255984 KB |
Output is correct |
16 |
Correct |
634 ms |
255932 KB |
Output is correct |
17 |
Correct |
112 ms |
252752 KB |
Output is correct |
18 |
Correct |
112 ms |
252996 KB |
Output is correct |
19 |
Correct |
117 ms |
253008 KB |
Output is correct |
20 |
Correct |
120 ms |
252980 KB |
Output is correct |
21 |
Correct |
169 ms |
253052 KB |
Output is correct |
22 |
Correct |
611 ms |
255868 KB |
Output is correct |
23 |
Correct |
485 ms |
255848 KB |
Output is correct |
24 |
Correct |
398 ms |
255456 KB |
Output is correct |
25 |
Correct |
460 ms |
255928 KB |
Output is correct |
26 |
Correct |
450 ms |
255924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
253008 KB |
Output is correct |
2 |
Correct |
110 ms |
252924 KB |
Output is correct |
3 |
Correct |
113 ms |
252864 KB |
Output is correct |
4 |
Correct |
112 ms |
252968 KB |
Output is correct |
5 |
Correct |
110 ms |
253008 KB |
Output is correct |
6 |
Correct |
111 ms |
253020 KB |
Output is correct |
7 |
Correct |
152 ms |
252924 KB |
Output is correct |
8 |
Correct |
112 ms |
253048 KB |
Output is correct |
9 |
Correct |
111 ms |
252756 KB |
Output is correct |
10 |
Correct |
110 ms |
252948 KB |
Output is correct |
11 |
Correct |
441 ms |
255960 KB |
Output is correct |
12 |
Correct |
357 ms |
254920 KB |
Output is correct |
13 |
Correct |
410 ms |
255480 KB |
Output is correct |
14 |
Correct |
461 ms |
256052 KB |
Output is correct |
15 |
Correct |
487 ms |
255984 KB |
Output is correct |
16 |
Correct |
634 ms |
255932 KB |
Output is correct |
17 |
Correct |
112 ms |
252752 KB |
Output is correct |
18 |
Correct |
112 ms |
252996 KB |
Output is correct |
19 |
Correct |
117 ms |
253008 KB |
Output is correct |
20 |
Correct |
120 ms |
252980 KB |
Output is correct |
21 |
Correct |
169 ms |
253052 KB |
Output is correct |
22 |
Correct |
611 ms |
255868 KB |
Output is correct |
23 |
Correct |
485 ms |
255848 KB |
Output is correct |
24 |
Correct |
398 ms |
255456 KB |
Output is correct |
25 |
Correct |
460 ms |
255928 KB |
Output is correct |
26 |
Correct |
450 ms |
255924 KB |
Output is correct |
27 |
Correct |
121 ms |
253012 KB |
Output is correct |
28 |
Correct |
122 ms |
253028 KB |
Output is correct |
29 |
Correct |
119 ms |
253008 KB |
Output is correct |
30 |
Correct |
120 ms |
252820 KB |
Output is correct |
31 |
Correct |
238 ms |
253120 KB |
Output is correct |
32 |
Correct |
138 ms |
253016 KB |
Output is correct |
33 |
Correct |
139 ms |
253068 KB |
Output is correct |
34 |
Correct |
1605 ms |
255780 KB |
Output is correct |
35 |
Correct |
1006 ms |
255612 KB |
Output is correct |
36 |
Correct |
992 ms |
255932 KB |
Output is correct |
37 |
Correct |
575 ms |
255920 KB |
Output is correct |
38 |
Correct |
413 ms |
255932 KB |
Output is correct |
39 |
Correct |
320 ms |
254624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
253008 KB |
Output is correct |
2 |
Correct |
110 ms |
252924 KB |
Output is correct |
3 |
Correct |
113 ms |
252864 KB |
Output is correct |
4 |
Correct |
112 ms |
252968 KB |
Output is correct |
5 |
Correct |
110 ms |
253008 KB |
Output is correct |
6 |
Correct |
111 ms |
253020 KB |
Output is correct |
7 |
Correct |
152 ms |
252924 KB |
Output is correct |
8 |
Correct |
112 ms |
253048 KB |
Output is correct |
9 |
Correct |
111 ms |
252756 KB |
Output is correct |
10 |
Correct |
110 ms |
252948 KB |
Output is correct |
11 |
Correct |
441 ms |
255960 KB |
Output is correct |
12 |
Correct |
357 ms |
254920 KB |
Output is correct |
13 |
Correct |
410 ms |
255480 KB |
Output is correct |
14 |
Correct |
461 ms |
256052 KB |
Output is correct |
15 |
Correct |
487 ms |
255984 KB |
Output is correct |
16 |
Correct |
634 ms |
255932 KB |
Output is correct |
17 |
Correct |
112 ms |
252752 KB |
Output is correct |
18 |
Correct |
112 ms |
252996 KB |
Output is correct |
19 |
Correct |
117 ms |
253008 KB |
Output is correct |
20 |
Correct |
120 ms |
252980 KB |
Output is correct |
21 |
Correct |
169 ms |
253052 KB |
Output is correct |
22 |
Correct |
611 ms |
255868 KB |
Output is correct |
23 |
Correct |
485 ms |
255848 KB |
Output is correct |
24 |
Correct |
398 ms |
255456 KB |
Output is correct |
25 |
Correct |
460 ms |
255928 KB |
Output is correct |
26 |
Correct |
450 ms |
255924 KB |
Output is correct |
27 |
Correct |
121 ms |
253012 KB |
Output is correct |
28 |
Correct |
122 ms |
253028 KB |
Output is correct |
29 |
Correct |
119 ms |
253008 KB |
Output is correct |
30 |
Correct |
120 ms |
252820 KB |
Output is correct |
31 |
Correct |
238 ms |
253120 KB |
Output is correct |
32 |
Correct |
138 ms |
253016 KB |
Output is correct |
33 |
Correct |
139 ms |
253068 KB |
Output is correct |
34 |
Correct |
1605 ms |
255780 KB |
Output is correct |
35 |
Correct |
1006 ms |
255612 KB |
Output is correct |
36 |
Correct |
992 ms |
255932 KB |
Output is correct |
37 |
Correct |
575 ms |
255920 KB |
Output is correct |
38 |
Correct |
413 ms |
255932 KB |
Output is correct |
39 |
Correct |
320 ms |
254624 KB |
Output is correct |
40 |
Correct |
325 ms |
253268 KB |
Output is correct |
41 |
Correct |
511 ms |
253228 KB |
Output is correct |
42 |
Correct |
224 ms |
253256 KB |
Output is correct |
43 |
Correct |
227 ms |
253268 KB |
Output is correct |
44 |
Execution timed out |
2016 ms |
256268 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
253008 KB |
Output is correct |
2 |
Correct |
128 ms |
253232 KB |
Output is correct |
3 |
Correct |
126 ms |
253008 KB |
Output is correct |
4 |
Correct |
124 ms |
252904 KB |
Output is correct |
5 |
Correct |
161 ms |
253264 KB |
Output is correct |
6 |
Correct |
123 ms |
253180 KB |
Output is correct |
7 |
Correct |
156 ms |
253012 KB |
Output is correct |
8 |
Correct |
126 ms |
253004 KB |
Output is correct |
9 |
Correct |
150 ms |
252844 KB |
Output is correct |
10 |
Correct |
114 ms |
252872 KB |
Output is correct |
11 |
Correct |
110 ms |
253012 KB |
Output is correct |
12 |
Correct |
129 ms |
253012 KB |
Output is correct |
13 |
Correct |
131 ms |
253336 KB |
Output is correct |
14 |
Correct |
163 ms |
253072 KB |
Output is correct |
15 |
Correct |
150 ms |
252884 KB |
Output is correct |
16 |
Correct |
168 ms |
253052 KB |
Output is correct |
17 |
Correct |
143 ms |
253012 KB |
Output is correct |
18 |
Correct |
167 ms |
253024 KB |
Output is correct |
19 |
Correct |
142 ms |
253264 KB |
Output is correct |
20 |
Correct |
140 ms |
253016 KB |
Output is correct |
21 |
Correct |
131 ms |
253044 KB |
Output is correct |
22 |
Correct |
135 ms |
253064 KB |
Output is correct |
23 |
Correct |
138 ms |
253144 KB |
Output is correct |
24 |
Correct |
139 ms |
253044 KB |
Output is correct |
25 |
Correct |
142 ms |
252888 KB |
Output is correct |
26 |
Correct |
985 ms |
253744 KB |
Output is correct |
27 |
Correct |
718 ms |
253524 KB |
Output is correct |
28 |
Correct |
611 ms |
253500 KB |
Output is correct |
29 |
Correct |
459 ms |
253328 KB |
Output is correct |
30 |
Correct |
387 ms |
253268 KB |
Output is correct |
31 |
Correct |
593 ms |
253228 KB |
Output is correct |
32 |
Correct |
296 ms |
253104 KB |
Output is correct |
33 |
Correct |
249 ms |
253208 KB |
Output is correct |
34 |
Correct |
287 ms |
253528 KB |
Output is correct |
35 |
Correct |
137 ms |
253016 KB |
Output is correct |
36 |
Correct |
137 ms |
253068 KB |
Output is correct |
37 |
Correct |
260 ms |
253264 KB |
Output is correct |
38 |
Correct |
195 ms |
253012 KB |
Output is correct |
39 |
Correct |
170 ms |
253264 KB |
Output is correct |
40 |
Correct |
111 ms |
253008 KB |
Output is correct |
41 |
Correct |
110 ms |
252924 KB |
Output is correct |
42 |
Correct |
113 ms |
252864 KB |
Output is correct |
43 |
Correct |
112 ms |
252968 KB |
Output is correct |
44 |
Correct |
110 ms |
253008 KB |
Output is correct |
45 |
Correct |
111 ms |
253020 KB |
Output is correct |
46 |
Correct |
152 ms |
252924 KB |
Output is correct |
47 |
Correct |
112 ms |
253048 KB |
Output is correct |
48 |
Correct |
111 ms |
252756 KB |
Output is correct |
49 |
Correct |
110 ms |
252948 KB |
Output is correct |
50 |
Correct |
441 ms |
255960 KB |
Output is correct |
51 |
Correct |
357 ms |
254920 KB |
Output is correct |
52 |
Correct |
410 ms |
255480 KB |
Output is correct |
53 |
Correct |
461 ms |
256052 KB |
Output is correct |
54 |
Correct |
487 ms |
255984 KB |
Output is correct |
55 |
Correct |
634 ms |
255932 KB |
Output is correct |
56 |
Correct |
112 ms |
252752 KB |
Output is correct |
57 |
Correct |
112 ms |
252996 KB |
Output is correct |
58 |
Correct |
117 ms |
253008 KB |
Output is correct |
59 |
Correct |
120 ms |
252980 KB |
Output is correct |
60 |
Correct |
169 ms |
253052 KB |
Output is correct |
61 |
Correct |
611 ms |
255868 KB |
Output is correct |
62 |
Correct |
485 ms |
255848 KB |
Output is correct |
63 |
Correct |
398 ms |
255456 KB |
Output is correct |
64 |
Correct |
460 ms |
255928 KB |
Output is correct |
65 |
Correct |
450 ms |
255924 KB |
Output is correct |
66 |
Correct |
121 ms |
253012 KB |
Output is correct |
67 |
Correct |
122 ms |
253028 KB |
Output is correct |
68 |
Correct |
119 ms |
253008 KB |
Output is correct |
69 |
Correct |
120 ms |
252820 KB |
Output is correct |
70 |
Correct |
238 ms |
253120 KB |
Output is correct |
71 |
Correct |
138 ms |
253016 KB |
Output is correct |
72 |
Correct |
139 ms |
253068 KB |
Output is correct |
73 |
Correct |
1605 ms |
255780 KB |
Output is correct |
74 |
Correct |
1006 ms |
255612 KB |
Output is correct |
75 |
Correct |
992 ms |
255932 KB |
Output is correct |
76 |
Correct |
575 ms |
255920 KB |
Output is correct |
77 |
Correct |
413 ms |
255932 KB |
Output is correct |
78 |
Correct |
320 ms |
254624 KB |
Output is correct |
79 |
Correct |
325 ms |
253268 KB |
Output is correct |
80 |
Correct |
511 ms |
253228 KB |
Output is correct |
81 |
Correct |
224 ms |
253256 KB |
Output is correct |
82 |
Correct |
227 ms |
253268 KB |
Output is correct |
83 |
Execution timed out |
2016 ms |
256268 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |