#include <bits/stdc++.h>
using namespace std ;
#define ll long long
#define FOR(i ,a , b) for(int i = a ; i <= b ; i++)
#define name "teamcontest"
#define pb push_back
#define all(a) a.begin() , a.end()
#define bit(mask , i) ((mask >> i) & 1)
#define fi first
#define se second
const ll N = 1e6 + 5 ;
const ll LOG = 20 ;
const ll MOD = 1e9 + 7 ;
ll n ;
struct Point
{
ll a , b , c ;
}x[N];
bool cmd(Point x , Point y)
{
if(x.a != y.a) return x.a < y.a ;
if(x.b != y.b) return x.b < y.b ;
return x.c < y.c ;
}
struct fenwick
{
ll f[500005] , n ;
void init(int _n)
{
n = _n ;
memset(f , -1 , sizeof f) ;
}
void update(ll i , ll x)
{
while(i < n)
{
f[i] = max(f[i] , x);
i += i & (-i) ;
}
}
ll getmax(ll i)
{
ll res = -1 ;
while(i)
{
res = max(res , f[i]) ;
i -= i &(-i) ;
}
return res ;
}
}fen;
vector<ll> rrhB ;
#define lo lower_bound
namespace sub2
{
ll getval(ll x)
{
return lower_bound(rrhB.begin(), rrhB.end(), x) - rrhB.begin() + 1;
}
void sol()
{
rrhB.clear();
FOR(i,1,n)
{
rrhB.push_back(x[i].b);
rrhB.push_back(x[i].b - 1);
}
sort(rrhB.begin(), rrhB.end());
rrhB.erase(unique(rrhB.begin(), rrhB.end()), rrhB.end());
ll ans = -1;
FOR(i,3,n)
{
ll cost = -1;
fen.init((int)rrhB.size() + 2);
FOR(j,1,i-1)
{
if(x[i].a == x[j].a) continue;
if(x[j].b > x[i].b)
{
ll C = fen.getmax(getval(x[j].b - 1));
if(C > x[j].c && C > x[i].c)
cost = max(cost, x[i].a + x[j].b + C);
}
fen.update(getval(x[j].b), x[j].c);
}
ans = max(ans, cost);
}
cout << ans;
}
bool checksub()
{
return n <= 4000;
}
}
namespace sub4
{
bool f[21][21][21] ;
Point X[N] ;
void sol()
{
FOR(i , 1, n) f[x[i].a][x[i].b][x[i].c] = 1 ;
ll cnt = 0;
FOR(i ,1, 20)
FOR(j ,1,20)
FOR(z , 1 , 20)
if(f[i][j][z]) X[++cnt] = {i , j , z} ;
ll ans = -1 ;
sort(X + 1 , X + cnt + 1 , cmd) ;
// cout << cnt <<'\n';
// FOR(i , 1,cnt) cout << X[i].a <<' '<< X[i].b <<' '<< X[i].c <<'\n';
FOR(i ,3 ,cnt)
{
ll cost = -1 ;
fen.init(100) ;
FOR(j , 1, i - 1)
{
if(X[i].a == X[j].a) continue ;
if(j == 1)
{
// cout << "update" << x[j].b <<"->"<< x[j].c <<'\n';
fen.update(X[j].b , X[j].c) ;
continue ;
}
if(X[j].b > X[i].b)
{
ll C = fen.getmax(X[j].b - 1) ;
// cout << x[j].b - 1 <<'\n';
if(C > X[j].c && C > X[i].c) cost = max(cost , X[i].a + X[j].b + fen.getmax(X[j].b - 1)) ;
}
fen.update(X[j].b , X[j].c) ;
}
ans = max(ans , cost) ;
}
cout << ans ;
}
bool checksub()
{
FOR(i , 1,n)
{
if(x[i].a > 20 || x[i].b > 20 || x[i].c > 20) return false ;
}
return true ;
}
}
int main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(0) ;
cout.tie(0) ;
if(fopen(name".inp" ,"r"))
{
freopen(name".inp" , "r" , stdin) ;
freopen(name".out" , "w" , stdout) ;
}
cin >> n ;
FOR(i ,1 , n) cin >> x[i].a >> x[i].b >> x[i].c ;
sort(x + 1 , x + n + 1 , cmd) ;
if(sub4::checksub())
sub4::sol() ;
else sub2::sol() ;
}
컴파일 시 표준 에러 (stderr) 메시지
team.cpp: In function 'int main()':
team.cpp:170:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
170 | freopen(name".inp" , "r" , stdin) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:171:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
171 | freopen(name".out" , "w" , stdout) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |