#include <bits/stdc++.h>
using namespace std;
using matr = array <int, 3>;
vector <matr> b;
int n;
int mx = -1;
void solve () {
sort(b.begin(), b.end());
int ptr = -1;
for (int i = 0; i < n; i++) { //i is larger than anything <= ptr in a
while (ptr + 1 < i && b[ptr + 1][0] < b[i][0]) ptr++;
if (ptr != 0) sort(b.begin(), b.begin() + ptr + 1, [] (matr &x, matr &y) {
return x[1] < y[1];
});
int mx2 = 0, ptr2 = -1;
for (int j = 0; j <= ptr; j++) {
if (b[j][1] <= b[i][1]) continue;
while (ptr2 + 1 < j && b[ptr2 + 1][1] < b[j][1]) {
ptr2++; mx2 = max(mx2, b[ptr2][2]);
}
if (mx2 > max(b[j][2], b[i][2])) {
mx = max(mx, mx2 + b[j][1] + b[i][0]);
}
}
}
}
int main () {
cin >> n; b.resize(n);
bool flag = 1;
for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> b[i][j], flag &= b[i][j] <= 20;
if (flag) {
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
n = b.size();
}
solve();
cout << mx << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
284 ms |
592 KB |
Output is correct |
27 |
Correct |
172 ms |
452 KB |
Output is correct |
28 |
Correct |
162 ms |
344 KB |
Output is correct |
29 |
Correct |
139 ms |
596 KB |
Output is correct |
30 |
Correct |
71 ms |
348 KB |
Output is correct |
31 |
Correct |
138 ms |
600 KB |
Output is correct |
32 |
Correct |
102 ms |
348 KB |
Output is correct |
33 |
Correct |
29 ms |
348 KB |
Output is correct |
34 |
Correct |
89 ms |
452 KB |
Output is correct |
35 |
Correct |
5 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
348 KB |
Output is correct |
37 |
Correct |
95 ms |
348 KB |
Output is correct |
38 |
Correct |
99 ms |
456 KB |
Output is correct |
39 |
Correct |
19 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
62 ms |
2840 KB |
Output is correct |
12 |
Correct |
40 ms |
2176 KB |
Output is correct |
13 |
Correct |
50 ms |
2396 KB |
Output is correct |
14 |
Correct |
61 ms |
2908 KB |
Output is correct |
15 |
Correct |
59 ms |
2896 KB |
Output is correct |
16 |
Correct |
56 ms |
3204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
62 ms |
2840 KB |
Output is correct |
12 |
Correct |
40 ms |
2176 KB |
Output is correct |
13 |
Correct |
50 ms |
2396 KB |
Output is correct |
14 |
Correct |
61 ms |
2908 KB |
Output is correct |
15 |
Correct |
59 ms |
2896 KB |
Output is correct |
16 |
Correct |
56 ms |
3204 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
18 ms |
448 KB |
Output is correct |
22 |
Correct |
465 ms |
3308 KB |
Output is correct |
23 |
Correct |
74 ms |
2916 KB |
Output is correct |
24 |
Correct |
58 ms |
2644 KB |
Output is correct |
25 |
Correct |
75 ms |
3152 KB |
Output is correct |
26 |
Correct |
62 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
62 ms |
2840 KB |
Output is correct |
12 |
Correct |
40 ms |
2176 KB |
Output is correct |
13 |
Correct |
50 ms |
2396 KB |
Output is correct |
14 |
Correct |
61 ms |
2908 KB |
Output is correct |
15 |
Correct |
59 ms |
2896 KB |
Output is correct |
16 |
Correct |
56 ms |
3204 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
18 ms |
448 KB |
Output is correct |
22 |
Correct |
465 ms |
3308 KB |
Output is correct |
23 |
Correct |
74 ms |
2916 KB |
Output is correct |
24 |
Correct |
58 ms |
2644 KB |
Output is correct |
25 |
Correct |
75 ms |
3152 KB |
Output is correct |
26 |
Correct |
62 ms |
3156 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
440 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
115 ms |
1012 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
348 KB |
Output is correct |
34 |
Execution timed out |
2005 ms |
3500 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
62 ms |
2840 KB |
Output is correct |
12 |
Correct |
40 ms |
2176 KB |
Output is correct |
13 |
Correct |
50 ms |
2396 KB |
Output is correct |
14 |
Correct |
61 ms |
2908 KB |
Output is correct |
15 |
Correct |
59 ms |
2896 KB |
Output is correct |
16 |
Correct |
56 ms |
3204 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
18 ms |
448 KB |
Output is correct |
22 |
Correct |
465 ms |
3308 KB |
Output is correct |
23 |
Correct |
74 ms |
2916 KB |
Output is correct |
24 |
Correct |
58 ms |
2644 KB |
Output is correct |
25 |
Correct |
75 ms |
3152 KB |
Output is correct |
26 |
Correct |
62 ms |
3156 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
440 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
115 ms |
1012 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
348 KB |
Output is correct |
34 |
Execution timed out |
2005 ms |
3500 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
284 ms |
592 KB |
Output is correct |
27 |
Correct |
172 ms |
452 KB |
Output is correct |
28 |
Correct |
162 ms |
344 KB |
Output is correct |
29 |
Correct |
139 ms |
596 KB |
Output is correct |
30 |
Correct |
71 ms |
348 KB |
Output is correct |
31 |
Correct |
138 ms |
600 KB |
Output is correct |
32 |
Correct |
102 ms |
348 KB |
Output is correct |
33 |
Correct |
29 ms |
348 KB |
Output is correct |
34 |
Correct |
89 ms |
452 KB |
Output is correct |
35 |
Correct |
5 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
348 KB |
Output is correct |
37 |
Correct |
95 ms |
348 KB |
Output is correct |
38 |
Correct |
99 ms |
456 KB |
Output is correct |
39 |
Correct |
19 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
62 ms |
2840 KB |
Output is correct |
51 |
Correct |
40 ms |
2176 KB |
Output is correct |
52 |
Correct |
50 ms |
2396 KB |
Output is correct |
53 |
Correct |
61 ms |
2908 KB |
Output is correct |
54 |
Correct |
59 ms |
2896 KB |
Output is correct |
55 |
Correct |
56 ms |
3204 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
432 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
18 ms |
448 KB |
Output is correct |
61 |
Correct |
465 ms |
3308 KB |
Output is correct |
62 |
Correct |
74 ms |
2916 KB |
Output is correct |
63 |
Correct |
58 ms |
2644 KB |
Output is correct |
64 |
Correct |
75 ms |
3152 KB |
Output is correct |
65 |
Correct |
62 ms |
3156 KB |
Output is correct |
66 |
Correct |
1 ms |
344 KB |
Output is correct |
67 |
Correct |
1 ms |
600 KB |
Output is correct |
68 |
Correct |
1 ms |
440 KB |
Output is correct |
69 |
Correct |
1 ms |
344 KB |
Output is correct |
70 |
Correct |
115 ms |
1012 KB |
Output is correct |
71 |
Correct |
5 ms |
344 KB |
Output is correct |
72 |
Correct |
5 ms |
348 KB |
Output is correct |
73 |
Execution timed out |
2005 ms |
3500 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |