#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cmplx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cout << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cout << #arr; FR(_i, n) cout << ' ' << arr[_i]; cout << endl;}
typedef array<int, 3> trip;
const int MN = 4005;
int n;
vector<trip> vec;
vi ys, zs;
int mxZPref[MN], mxYPref[MN], mnZ[MN], mxZ[MN];
int main(){
boost();
cin >> n;
FR(i, n){
int a, b, c;
cin >> a >> b >> c;
vec.pb({a, b, c});
ys.pb(b);
zs.pb(c);
}
UNIQUE(vec);
UNIQUE(ys);
UNIQUE(zs);
int ans = -1;
int lst = 0, prvX = vec[0][0];
FR(i, SZ(vec)){
if(vec[i][0] != prvX){
FOR(j, lst, i){
auto [x, y, z] = vec[j];
int yPos = lbv(ys, y);
int zPos = lbv(zs, z);
int mz = 0;
FR(k, yPos) mz = max(mz, mxZPref[k]);
if(mz) mxZ[yPos] = max(mxZ[yPos], mz);
mxZPref[yPos] = max(mxZPref[yPos], z);
mnZ[yPos] = min(mnZ[yPos], z);
int mxY = 0;
FR(k, zPos) mxY = max(mxY, mxYPref[k]);
if(mxY){
int yp1 = lbv(ys, mxY);
mxZ[yp1] = max(mxZ[yp1], z);
}
mxYPref[zPos] = max(mxYPref[zPos], y);
}
prvX = vec[i][0];
lst = i;
}
auto [x, y, z] = vec[i];
int yPos = lbv(ys, y);
int mxSum = 0;
FOR(j, yPos+1, n) mxSum = max(mxSum, (ys[j] + mxZ[j]) * (mxZ[j] > z) * (mnZ[j] > z));
if(mxSum) ans = max(ans, mxSum + x);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |