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,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 1.5e5 + 5;
int n;
int a[SIZE][3];
pair<int, int> p[3][SIZE];
bool is[SIZE];
void solve() {
cin >> n;
FOR (j, 1, n) FOR (i, 0, 2) {
cin >> p[i][j].F;
p[i][j].S = j;
a[j][i] = p[i][j].F;
}
FOR (i, 0, 2) sort(p[i] + 1, p[i] + n + 1, greater<pair<int, int>>());
for (int i[3] = {1, 1, 1};;) {
FOR (j, 0, 2) while (i[j] <= n && is[p[j][i[j]].S]) i[j]++;
if (*max_element(i, i + 3) > n) break;
int x = p[0][i[0]].S, y = p[1][i[1]].S, z = p[2][i[2]].S;
debug(x, y, z);
if (a[x][0] == max(a[y][0], a[z][0])) {is[x] = 1; continue;}
if (a[y][1] == max(a[x][1], a[z][1])) {is[y] = 1; continue;}
if (a[z][2] == max(a[x][2], a[y][2])) {is[z] = 1; continue;}
cout << a[x][0] + a[y][1] + a[z][2] << '\n';
return;
}
cout << "-1\n";
}
int main() {
Waimai;
solve();
}
Compilation message (stderr)
team.cpp: In function 'void solve()':
team.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 7122
| ^~~~
team.cpp:40:9: note: in expansion of macro 'debug'
40 | debug(x, y, z);
| ^~~~~
# | 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... |