This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define pill pair<ll, ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e5 + 1;
const ll hsh[2] = {1555555699, 1222222763};
const ll P = 113;
ll n;
ll a[N], b[N], c[N];
vector<pill> g[3][310];
int main() {
speed;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i] >> c[i];
g[0][a[i]].pb(mp(b[i], c[i]));
g[1][b[i]].pb(mp(a[i], c[i]));
g[2][c[i]].pb(mp(a[i], b[i]));
}
for(int j = 0; j < 3; j++) {
for(int x = 0; x <= 300; x++) {
sort(g[j][x].begin(), g[j][x].end());
for(int i = 1; i < g[j][x].size(); i++) {
g[j][x][i].s = min(g[j][x][i].s, g[j][x][i - 1].s);
}
g[j][x].erase(unique(g[j][x].begin(), g[j][x].end()), g[j][x].end());
}
}
ll sum = -1;
if(n <= 300) {
for(int j = 0; j < n; j++) {
for(int i = 0; i < n; i++) {
for(int k = 0; k < n; k++) {
if(a[j] > max(a[i], a[k]) && b[i] > max(b[j], b[k]) && c[k] > max(c[j], c[i])) {
sum = max(sum, a[j] + b[i] + c[k]);
}
}
}
}
cout << sum;
} else {
for(int i = 1; i <= 300; i++) {
for(int j = 1; j <= 300; j++) {
for(int k = 1; k <= 300; k++) {
ll l = 0, r = ((ll)g[0][i].size()) - 1, ans = -1, ans2 = -1, ans3 = -1;
while(l <= r) {
ll m = (l + r) >> 1ll;
if(g[0][i][m].f < j) {
ans = m;
l = m + 1;
} else r = m - 1;
}
if(ans == -1)continue;
l = 0, r = ((ll)g[1][j].size()) - 1;
while(l <= r) {
ll m = (l + r) >> 1ll;
if(g[1][j][m].f < i) {
ans2 = m;
l = m + 1;
} else r = m - 1;
}
if(ans2 == -1)continue;
l = 0, r = ((ll)g[2][k].size()) - 1;
while(l <= r) {
ll m = (l + r) >> 1ll;
if(g[2][k][m].f < i) {
ans3 = m;
l = m + 1;
} else r = m - 1;
}
if(ans3 == -1)continue;
if(g[0][i][ans].s < k && g[1][j][ans2].s < k && g[2][k][ans3].s < j) {
sum = max(sum, (ll)(i + j + k));
}
}
}
}
cout << sum;
}
}
Compilation message (stderr)
team.cpp: In function 'int main()':
team.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 1; i < g[j][x].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
# | 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... |