#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);
sort(all(beavers), compX);
n = (int)beavers.size();
int bestScore = -1;
int jStart = 1;
loop(i, n) {
while (jStart < n && beavers[jStart].x >= beavers[i].x) jStart++;
const Beaver& beaver1 = beavers[i];
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);
}
//sort(all(beaversLeft), greater());
int m = (int)beaversLeft.size();
int kStart = 1;
for (int j = 0; j < m; j++) {
while (kStart < m && beaversLeft[j].first <= beaversLeft[kStart].first) kStart++;
for (int k = kStart; k < m; k++) {
if (beaversLeft[j].first == beaversLeft[k].first) continue;
int y[3] = { beaver1.y, beaversLeft[j].first, beaversLeft[k].first };
int z[3] = { beaver1.z, beaversLeft[j].second, beaversLeft[k].second };
int maxX = 0;
int maxY = getMax(y, 3);
int maxZ = getMax(z, 3);
if (maxX == maxY || maxX == maxZ || maxY == maxZ || maxY == -1 || maxZ == -1) continue;
bestScore = max(bestScore, beaver1.x + y[maxY] + z[maxZ]);
}
}
}
std::cout << bestScore << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
436 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
0 ms |
440 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 |
17 ms |
492 KB |
Output is correct |
15 |
Correct |
7 ms |
344 KB |
Output is correct |
16 |
Correct |
14 ms |
348 KB |
Output is correct |
17 |
Correct |
15 ms |
348 KB |
Output is correct |
18 |
Correct |
16 ms |
348 KB |
Output is correct |
19 |
Correct |
16 ms |
480 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
12 ms |
480 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
7 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
436 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
0 ms |
440 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 |
17 ms |
492 KB |
Output is correct |
15 |
Correct |
7 ms |
344 KB |
Output is correct |
16 |
Correct |
14 ms |
348 KB |
Output is correct |
17 |
Correct |
15 ms |
348 KB |
Output is correct |
18 |
Correct |
16 ms |
348 KB |
Output is correct |
19 |
Correct |
16 ms |
480 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
12 ms |
480 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
7 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Execution timed out |
2025 ms |
856 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
63 ms |
1108 KB |
Output is correct |
12 |
Correct |
28 ms |
856 KB |
Output is correct |
13 |
Correct |
27 ms |
860 KB |
Output is correct |
14 |
Correct |
35 ms |
1108 KB |
Output is correct |
15 |
Correct |
32 ms |
1112 KB |
Output is correct |
16 |
Correct |
30 ms |
1068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
63 ms |
1108 KB |
Output is correct |
12 |
Correct |
28 ms |
856 KB |
Output is correct |
13 |
Correct |
27 ms |
860 KB |
Output is correct |
14 |
Correct |
35 ms |
1108 KB |
Output is correct |
15 |
Correct |
32 ms |
1112 KB |
Output is correct |
16 |
Correct |
30 ms |
1068 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
374 ms |
604 KB |
Output is correct |
22 |
Execution timed out |
2070 ms |
1740 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
63 ms |
1108 KB |
Output is correct |
12 |
Correct |
28 ms |
856 KB |
Output is correct |
13 |
Correct |
27 ms |
860 KB |
Output is correct |
14 |
Correct |
35 ms |
1108 KB |
Output is correct |
15 |
Correct |
32 ms |
1112 KB |
Output is correct |
16 |
Correct |
30 ms |
1068 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
374 ms |
604 KB |
Output is correct |
22 |
Execution timed out |
2070 ms |
1740 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
63 ms |
1108 KB |
Output is correct |
12 |
Correct |
28 ms |
856 KB |
Output is correct |
13 |
Correct |
27 ms |
860 KB |
Output is correct |
14 |
Correct |
35 ms |
1108 KB |
Output is correct |
15 |
Correct |
32 ms |
1112 KB |
Output is correct |
16 |
Correct |
30 ms |
1068 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
374 ms |
604 KB |
Output is correct |
22 |
Execution timed out |
2070 ms |
1740 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
436 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
0 ms |
440 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 |
17 ms |
492 KB |
Output is correct |
15 |
Correct |
7 ms |
344 KB |
Output is correct |
16 |
Correct |
14 ms |
348 KB |
Output is correct |
17 |
Correct |
15 ms |
348 KB |
Output is correct |
18 |
Correct |
16 ms |
348 KB |
Output is correct |
19 |
Correct |
16 ms |
480 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
12 ms |
480 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
7 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Execution timed out |
2025 ms |
856 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |