This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 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;
int prevX = -1;
int i = 0;
while (i < n) {
while (jStart < n && beavers[i].x <= beavers[jStart].x) jStart++;
const Beaver& beaver1 = beavers[i];
//vector<Beaver> beaversLeft;
// for (int j = jStart; j < n; j++) beaversLeft.push_back(beavers[j]);
//sort(all(beaversLeft));
for (int j = jStart; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (beavers[j].y == beavers[k].y) continue;
int y[3] = { beavers[i].y, beavers[j].y, beavers[k].y };
int z[3] = { beavers[i].z, beavers[j].z, beavers[k].z };
int maxY = getMax(y, 3);
int maxZ = getMax(z, 3);
if (maxY == maxZ || maxY == -1 || maxZ == -1) continue;
bestScore = max(bestScore, beaver1.x + y[maxY] + z[maxZ]);
}
}
prevX = beavers[i].x;
i++;
//while (i < n - 1 && beavers[i].x == prevX && (beavers[i + 1].y <= beavers[i].y && beavers[i + 1].z <= beavers[i].z)) i++;
}
std::cout << bestScore << endl;
return 0;
}
Compilation message (stderr)
team.cpp: In function 'int main()':
team.cpp:83:9: warning: variable 'prevX' set but not used [-Wunused-but-set-variable]
83 | int prevX = -1;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |