#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;
int C;
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;
C = max({C, a[i], b[i], c[i]});
}
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 R;
if (C < 3000)
R = 1000;
else
R = N - 1;
int ans = -1;
for (int i = 1;i <= n;i++) {
for (int j = R;j > a[i];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]]);
break;
}
}
}
cout << ans << '\n';
}
return 0;
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:64:4: warning: 'C' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | if (C < 3000)
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
252924 KB |
Output is correct |
2 |
Correct |
110 ms |
253000 KB |
Output is correct |
3 |
Correct |
110 ms |
253008 KB |
Output is correct |
4 |
Correct |
110 ms |
252780 KB |
Output is correct |
5 |
Correct |
112 ms |
253012 KB |
Output is correct |
6 |
Correct |
113 ms |
253012 KB |
Output is correct |
7 |
Correct |
112 ms |
253000 KB |
Output is correct |
8 |
Correct |
110 ms |
252860 KB |
Output is correct |
9 |
Correct |
119 ms |
252912 KB |
Output is correct |
10 |
Correct |
116 ms |
252772 KB |
Output is correct |
11 |
Correct |
110 ms |
253008 KB |
Output is correct |
12 |
Correct |
110 ms |
253008 KB |
Output is correct |
13 |
Correct |
110 ms |
253008 KB |
Output is correct |
14 |
Correct |
115 ms |
253060 KB |
Output is correct |
15 |
Correct |
113 ms |
253032 KB |
Output is correct |
16 |
Correct |
118 ms |
252992 KB |
Output is correct |
17 |
Correct |
113 ms |
253036 KB |
Output is correct |
18 |
Correct |
114 ms |
252808 KB |
Output is correct |
19 |
Correct |
113 ms |
253012 KB |
Output is correct |
20 |
Correct |
114 ms |
252992 KB |
Output is correct |
21 |
Correct |
121 ms |
253032 KB |
Output is correct |
22 |
Correct |
120 ms |
253056 KB |
Output is correct |
23 |
Correct |
114 ms |
253012 KB |
Output is correct |
24 |
Correct |
116 ms |
252896 KB |
Output is correct |
25 |
Correct |
112 ms |
252872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
252924 KB |
Output is correct |
2 |
Correct |
110 ms |
253000 KB |
Output is correct |
3 |
Correct |
110 ms |
253008 KB |
Output is correct |
4 |
Correct |
110 ms |
252780 KB |
Output is correct |
5 |
Correct |
112 ms |
253012 KB |
Output is correct |
6 |
Correct |
113 ms |
253012 KB |
Output is correct |
7 |
Correct |
112 ms |
253000 KB |
Output is correct |
8 |
Correct |
110 ms |
252860 KB |
Output is correct |
9 |
Correct |
119 ms |
252912 KB |
Output is correct |
10 |
Correct |
116 ms |
252772 KB |
Output is correct |
11 |
Correct |
110 ms |
253008 KB |
Output is correct |
12 |
Correct |
110 ms |
253008 KB |
Output is correct |
13 |
Correct |
110 ms |
253008 KB |
Output is correct |
14 |
Correct |
115 ms |
253060 KB |
Output is correct |
15 |
Correct |
113 ms |
253032 KB |
Output is correct |
16 |
Correct |
118 ms |
252992 KB |
Output is correct |
17 |
Correct |
113 ms |
253036 KB |
Output is correct |
18 |
Correct |
114 ms |
252808 KB |
Output is correct |
19 |
Correct |
113 ms |
253012 KB |
Output is correct |
20 |
Correct |
114 ms |
252992 KB |
Output is correct |
21 |
Correct |
121 ms |
253032 KB |
Output is correct |
22 |
Correct |
120 ms |
253056 KB |
Output is correct |
23 |
Correct |
114 ms |
253012 KB |
Output is correct |
24 |
Correct |
116 ms |
252896 KB |
Output is correct |
25 |
Correct |
112 ms |
252872 KB |
Output is correct |
26 |
Runtime error |
331 ms |
513740 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
253008 KB |
Output is correct |
2 |
Correct |
112 ms |
252948 KB |
Output is correct |
3 |
Correct |
114 ms |
252844 KB |
Output is correct |
4 |
Correct |
115 ms |
253000 KB |
Output is correct |
5 |
Correct |
114 ms |
253024 KB |
Output is correct |
6 |
Correct |
116 ms |
252996 KB |
Output is correct |
7 |
Correct |
111 ms |
252868 KB |
Output is correct |
8 |
Correct |
110 ms |
252756 KB |
Output is correct |
9 |
Correct |
116 ms |
252792 KB |
Output is correct |
10 |
Correct |
111 ms |
252956 KB |
Output is correct |
11 |
Correct |
366 ms |
255912 KB |
Output is correct |
12 |
Correct |
289 ms |
254912 KB |
Output is correct |
13 |
Correct |
324 ms |
255404 KB |
Output is correct |
14 |
Correct |
339 ms |
255932 KB |
Output is correct |
15 |
Correct |
342 ms |
255960 KB |
Output is correct |
16 |
Correct |
323 ms |
255928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
253008 KB |
Output is correct |
2 |
Correct |
112 ms |
252948 KB |
Output is correct |
3 |
Correct |
114 ms |
252844 KB |
Output is correct |
4 |
Correct |
115 ms |
253000 KB |
Output is correct |
5 |
Correct |
114 ms |
253024 KB |
Output is correct |
6 |
Correct |
116 ms |
252996 KB |
Output is correct |
7 |
Correct |
111 ms |
252868 KB |
Output is correct |
8 |
Correct |
110 ms |
252756 KB |
Output is correct |
9 |
Correct |
116 ms |
252792 KB |
Output is correct |
10 |
Correct |
111 ms |
252956 KB |
Output is correct |
11 |
Correct |
366 ms |
255912 KB |
Output is correct |
12 |
Correct |
289 ms |
254912 KB |
Output is correct |
13 |
Correct |
324 ms |
255404 KB |
Output is correct |
14 |
Correct |
339 ms |
255932 KB |
Output is correct |
15 |
Correct |
342 ms |
255960 KB |
Output is correct |
16 |
Correct |
323 ms |
255928 KB |
Output is correct |
17 |
Correct |
109 ms |
252756 KB |
Output is correct |
18 |
Correct |
109 ms |
252756 KB |
Output is correct |
19 |
Correct |
113 ms |
253008 KB |
Output is correct |
20 |
Correct |
116 ms |
253024 KB |
Output is correct |
21 |
Correct |
115 ms |
253012 KB |
Output is correct |
22 |
Correct |
382 ms |
255876 KB |
Output is correct |
23 |
Correct |
377 ms |
255928 KB |
Output is correct |
24 |
Correct |
296 ms |
255064 KB |
Output is correct |
25 |
Correct |
367 ms |
255828 KB |
Output is correct |
26 |
Correct |
384 ms |
255928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
253008 KB |
Output is correct |
2 |
Correct |
112 ms |
252948 KB |
Output is correct |
3 |
Correct |
114 ms |
252844 KB |
Output is correct |
4 |
Correct |
115 ms |
253000 KB |
Output is correct |
5 |
Correct |
114 ms |
253024 KB |
Output is correct |
6 |
Correct |
116 ms |
252996 KB |
Output is correct |
7 |
Correct |
111 ms |
252868 KB |
Output is correct |
8 |
Correct |
110 ms |
252756 KB |
Output is correct |
9 |
Correct |
116 ms |
252792 KB |
Output is correct |
10 |
Correct |
111 ms |
252956 KB |
Output is correct |
11 |
Correct |
366 ms |
255912 KB |
Output is correct |
12 |
Correct |
289 ms |
254912 KB |
Output is correct |
13 |
Correct |
324 ms |
255404 KB |
Output is correct |
14 |
Correct |
339 ms |
255932 KB |
Output is correct |
15 |
Correct |
342 ms |
255960 KB |
Output is correct |
16 |
Correct |
323 ms |
255928 KB |
Output is correct |
17 |
Correct |
109 ms |
252756 KB |
Output is correct |
18 |
Correct |
109 ms |
252756 KB |
Output is correct |
19 |
Correct |
113 ms |
253008 KB |
Output is correct |
20 |
Correct |
116 ms |
253024 KB |
Output is correct |
21 |
Correct |
115 ms |
253012 KB |
Output is correct |
22 |
Correct |
382 ms |
255876 KB |
Output is correct |
23 |
Correct |
377 ms |
255928 KB |
Output is correct |
24 |
Correct |
296 ms |
255064 KB |
Output is correct |
25 |
Correct |
367 ms |
255828 KB |
Output is correct |
26 |
Correct |
384 ms |
255928 KB |
Output is correct |
27 |
Correct |
151 ms |
253012 KB |
Output is correct |
28 |
Correct |
111 ms |
253028 KB |
Output is correct |
29 |
Correct |
112 ms |
253036 KB |
Output is correct |
30 |
Correct |
112 ms |
253012 KB |
Output is correct |
31 |
Correct |
119 ms |
253080 KB |
Output is correct |
32 |
Correct |
113 ms |
253264 KB |
Output is correct |
33 |
Correct |
112 ms |
252840 KB |
Output is correct |
34 |
Correct |
367 ms |
255672 KB |
Output is correct |
35 |
Correct |
381 ms |
255724 KB |
Output is correct |
36 |
Correct |
474 ms |
255920 KB |
Output is correct |
37 |
Correct |
385 ms |
255952 KB |
Output is correct |
38 |
Correct |
313 ms |
255924 KB |
Output is correct |
39 |
Correct |
256 ms |
254860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
253008 KB |
Output is correct |
2 |
Correct |
112 ms |
252948 KB |
Output is correct |
3 |
Correct |
114 ms |
252844 KB |
Output is correct |
4 |
Correct |
115 ms |
253000 KB |
Output is correct |
5 |
Correct |
114 ms |
253024 KB |
Output is correct |
6 |
Correct |
116 ms |
252996 KB |
Output is correct |
7 |
Correct |
111 ms |
252868 KB |
Output is correct |
8 |
Correct |
110 ms |
252756 KB |
Output is correct |
9 |
Correct |
116 ms |
252792 KB |
Output is correct |
10 |
Correct |
111 ms |
252956 KB |
Output is correct |
11 |
Correct |
366 ms |
255912 KB |
Output is correct |
12 |
Correct |
289 ms |
254912 KB |
Output is correct |
13 |
Correct |
324 ms |
255404 KB |
Output is correct |
14 |
Correct |
339 ms |
255932 KB |
Output is correct |
15 |
Correct |
342 ms |
255960 KB |
Output is correct |
16 |
Correct |
323 ms |
255928 KB |
Output is correct |
17 |
Correct |
109 ms |
252756 KB |
Output is correct |
18 |
Correct |
109 ms |
252756 KB |
Output is correct |
19 |
Correct |
113 ms |
253008 KB |
Output is correct |
20 |
Correct |
116 ms |
253024 KB |
Output is correct |
21 |
Correct |
115 ms |
253012 KB |
Output is correct |
22 |
Correct |
382 ms |
255876 KB |
Output is correct |
23 |
Correct |
377 ms |
255928 KB |
Output is correct |
24 |
Correct |
296 ms |
255064 KB |
Output is correct |
25 |
Correct |
367 ms |
255828 KB |
Output is correct |
26 |
Correct |
384 ms |
255928 KB |
Output is correct |
27 |
Correct |
151 ms |
253012 KB |
Output is correct |
28 |
Correct |
111 ms |
253028 KB |
Output is correct |
29 |
Correct |
112 ms |
253036 KB |
Output is correct |
30 |
Correct |
112 ms |
253012 KB |
Output is correct |
31 |
Correct |
119 ms |
253080 KB |
Output is correct |
32 |
Correct |
113 ms |
253264 KB |
Output is correct |
33 |
Correct |
112 ms |
252840 KB |
Output is correct |
34 |
Correct |
367 ms |
255672 KB |
Output is correct |
35 |
Correct |
381 ms |
255724 KB |
Output is correct |
36 |
Correct |
474 ms |
255920 KB |
Output is correct |
37 |
Correct |
385 ms |
255952 KB |
Output is correct |
38 |
Correct |
313 ms |
255924 KB |
Output is correct |
39 |
Correct |
256 ms |
254860 KB |
Output is correct |
40 |
Correct |
125 ms |
253288 KB |
Output is correct |
41 |
Correct |
122 ms |
253012 KB |
Output is correct |
42 |
Incorrect |
116 ms |
253100 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
252924 KB |
Output is correct |
2 |
Correct |
110 ms |
253000 KB |
Output is correct |
3 |
Correct |
110 ms |
253008 KB |
Output is correct |
4 |
Correct |
110 ms |
252780 KB |
Output is correct |
5 |
Correct |
112 ms |
253012 KB |
Output is correct |
6 |
Correct |
113 ms |
253012 KB |
Output is correct |
7 |
Correct |
112 ms |
253000 KB |
Output is correct |
8 |
Correct |
110 ms |
252860 KB |
Output is correct |
9 |
Correct |
119 ms |
252912 KB |
Output is correct |
10 |
Correct |
116 ms |
252772 KB |
Output is correct |
11 |
Correct |
110 ms |
253008 KB |
Output is correct |
12 |
Correct |
110 ms |
253008 KB |
Output is correct |
13 |
Correct |
110 ms |
253008 KB |
Output is correct |
14 |
Correct |
115 ms |
253060 KB |
Output is correct |
15 |
Correct |
113 ms |
253032 KB |
Output is correct |
16 |
Correct |
118 ms |
252992 KB |
Output is correct |
17 |
Correct |
113 ms |
253036 KB |
Output is correct |
18 |
Correct |
114 ms |
252808 KB |
Output is correct |
19 |
Correct |
113 ms |
253012 KB |
Output is correct |
20 |
Correct |
114 ms |
252992 KB |
Output is correct |
21 |
Correct |
121 ms |
253032 KB |
Output is correct |
22 |
Correct |
120 ms |
253056 KB |
Output is correct |
23 |
Correct |
114 ms |
253012 KB |
Output is correct |
24 |
Correct |
116 ms |
252896 KB |
Output is correct |
25 |
Correct |
112 ms |
252872 KB |
Output is correct |
26 |
Runtime error |
331 ms |
513740 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |