#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
int getMax(int* data, int size) {
bool isSame = false;
int best = 0;
for (int i = 1; i < size; i++) {
if (data[i] > data[best]) {
best = i;
isSame = false;
}
else if (data[i] == data[best])
isSame = true;
}
if (isSame) return -1;
return best;
}
struct Beaver {
int x = 0, y = 0, z = 0;
bool operator<(const Beaver& b) const {
return x > b.x || (x == b.x && y > b.y) || (x == b.x && y == b.y && z > b.z);
}
bool operator==(const Beaver& b) const {
return x == b.x && y == b.y && z == b.z;
}
};
bool compX(const Beaver& a, const Beaver& b) {
return a.x > b.x;
}
bool compY(const Beaver& a, const Beaver& b) {
return a.y > b.y || (a.y == b.y && a.z > b.z);
}
signed main() {
int n;
cin >> n;
set<Beaver> beaverSet;
vector<Beaver> beavers;
loop(i, n) {
int x, y, z;
cin >> x >> y >> z;
beaverSet.insert(Beaver{x, y, z});
}
for (auto beaver : beaverSet) beavers.push_back(beaver);
n = (int)beavers.size();
int bestScore = -1;
int jStart = 1;
loop(i, n) {
const Beaver& beaver1 = beavers[i];
while (jStart < n && beavers[jStart].x >= beavers[i].x)
jStart++;
set<ii, greater<ii>> beaversLeftList;
for (int j = jStart; j < n; j++)
beaversLeftList.insert({ beavers[j].y, beavers[j].z });
vii beaversLeft;
for (auto x : beaversLeftList) {
beaversLeft.push_back(x);
}
int m = (int)beaversLeft.size();
if (m == 0) break;
vi sufMaxZ(m + 1);
for (int j = m - 1; j >= 0; j--)
sufMaxZ[j] = max(sufMaxZ[j + 1], beaversLeft[j].second);
int kStart = 1;
for (int j = 0; j < m; j++) {
if (beaversLeft[j].first <= beaver1.y) continue;
while (kStart < m && beaversLeft[j].first <= beaversLeft[kStart].first)
kStart++;
if (kStart == m) break;
if (sufMaxZ[kStart] <= beaversLeft[j].second || sufMaxZ[kStart] <= beaver1.z) continue;
int score = beaver1.x + beaversLeft[j].first + sufMaxZ[kStart];
bestScore = max(score, bestScore);
}
}
std::cout << bestScore << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 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 |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
773 ms |
1136 KB |
Output is correct |
27 |
Correct |
764 ms |
1112 KB |
Output is correct |
28 |
Correct |
755 ms |
1124 KB |
Output is correct |
29 |
Correct |
699 ms |
1116 KB |
Output is correct |
30 |
Correct |
304 ms |
860 KB |
Output is correct |
31 |
Correct |
826 ms |
1140 KB |
Output is correct |
32 |
Correct |
512 ms |
860 KB |
Output is correct |
33 |
Correct |
7 ms |
600 KB |
Output is correct |
34 |
Correct |
421 ms |
1132 KB |
Output is correct |
35 |
Correct |
18 ms |
348 KB |
Output is correct |
36 |
Correct |
16 ms |
348 KB |
Output is correct |
37 |
Correct |
433 ms |
1032 KB |
Output is correct |
38 |
Correct |
457 ms |
1032 KB |
Output is correct |
39 |
Correct |
38 ms |
604 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 |
35 ms |
412 KB |
Output is correct |
12 |
Correct |
23 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
344 KB |
Output is correct |
14 |
Correct |
51 ms |
348 KB |
Output is correct |
15 |
Correct |
43 ms |
348 KB |
Output is correct |
16 |
Correct |
31 ms |
408 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 |
35 ms |
412 KB |
Output is correct |
12 |
Correct |
23 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
344 KB |
Output is correct |
14 |
Correct |
51 ms |
348 KB |
Output is correct |
15 |
Correct |
43 ms |
348 KB |
Output is correct |
16 |
Correct |
31 ms |
408 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
36 ms |
604 KB |
Output is correct |
22 |
Correct |
635 ms |
1172 KB |
Output is correct |
23 |
Correct |
61 ms |
512 KB |
Output is correct |
24 |
Correct |
44 ms |
560 KB |
Output is correct |
25 |
Correct |
50 ms |
484 KB |
Output is correct |
26 |
Correct |
46 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 |
35 ms |
412 KB |
Output is correct |
12 |
Correct |
23 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
344 KB |
Output is correct |
14 |
Correct |
51 ms |
348 KB |
Output is correct |
15 |
Correct |
43 ms |
348 KB |
Output is correct |
16 |
Correct |
31 ms |
408 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
36 ms |
604 KB |
Output is correct |
22 |
Correct |
635 ms |
1172 KB |
Output is correct |
23 |
Correct |
61 ms |
512 KB |
Output is correct |
24 |
Correct |
44 ms |
560 KB |
Output is correct |
25 |
Correct |
50 ms |
484 KB |
Output is correct |
26 |
Correct |
46 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
360 KB |
Output is correct |
31 |
Correct |
490 ms |
1040 KB |
Output is correct |
32 |
Correct |
26 ms |
584 KB |
Output is correct |
33 |
Correct |
20 ms |
348 KB |
Output is correct |
34 |
Execution timed out |
2059 ms |
21180 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 |
35 ms |
412 KB |
Output is correct |
12 |
Correct |
23 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
344 KB |
Output is correct |
14 |
Correct |
51 ms |
348 KB |
Output is correct |
15 |
Correct |
43 ms |
348 KB |
Output is correct |
16 |
Correct |
31 ms |
408 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
36 ms |
604 KB |
Output is correct |
22 |
Correct |
635 ms |
1172 KB |
Output is correct |
23 |
Correct |
61 ms |
512 KB |
Output is correct |
24 |
Correct |
44 ms |
560 KB |
Output is correct |
25 |
Correct |
50 ms |
484 KB |
Output is correct |
26 |
Correct |
46 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
360 KB |
Output is correct |
31 |
Correct |
490 ms |
1040 KB |
Output is correct |
32 |
Correct |
26 ms |
584 KB |
Output is correct |
33 |
Correct |
20 ms |
348 KB |
Output is correct |
34 |
Execution timed out |
2059 ms |
21180 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 |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
773 ms |
1136 KB |
Output is correct |
27 |
Correct |
764 ms |
1112 KB |
Output is correct |
28 |
Correct |
755 ms |
1124 KB |
Output is correct |
29 |
Correct |
699 ms |
1116 KB |
Output is correct |
30 |
Correct |
304 ms |
860 KB |
Output is correct |
31 |
Correct |
826 ms |
1140 KB |
Output is correct |
32 |
Correct |
512 ms |
860 KB |
Output is correct |
33 |
Correct |
7 ms |
600 KB |
Output is correct |
34 |
Correct |
421 ms |
1132 KB |
Output is correct |
35 |
Correct |
18 ms |
348 KB |
Output is correct |
36 |
Correct |
16 ms |
348 KB |
Output is correct |
37 |
Correct |
433 ms |
1032 KB |
Output is correct |
38 |
Correct |
457 ms |
1032 KB |
Output is correct |
39 |
Correct |
38 ms |
604 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 |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
35 ms |
412 KB |
Output is correct |
51 |
Correct |
23 ms |
348 KB |
Output is correct |
52 |
Correct |
26 ms |
344 KB |
Output is correct |
53 |
Correct |
51 ms |
348 KB |
Output is correct |
54 |
Correct |
43 ms |
348 KB |
Output is correct |
55 |
Correct |
31 ms |
408 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
2 ms |
348 KB |
Output is correct |
60 |
Correct |
36 ms |
604 KB |
Output is correct |
61 |
Correct |
635 ms |
1172 KB |
Output is correct |
62 |
Correct |
61 ms |
512 KB |
Output is correct |
63 |
Correct |
44 ms |
560 KB |
Output is correct |
64 |
Correct |
50 ms |
484 KB |
Output is correct |
65 |
Correct |
46 ms |
348 KB |
Output is correct |
66 |
Correct |
2 ms |
348 KB |
Output is correct |
67 |
Correct |
4 ms |
348 KB |
Output is correct |
68 |
Correct |
3 ms |
348 KB |
Output is correct |
69 |
Correct |
3 ms |
360 KB |
Output is correct |
70 |
Correct |
490 ms |
1040 KB |
Output is correct |
71 |
Correct |
26 ms |
584 KB |
Output is correct |
72 |
Correct |
20 ms |
348 KB |
Output is correct |
73 |
Execution timed out |
2059 ms |
21180 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |