#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;
vpii compr;
vi xs, ys;
int arr[MN][MN];
int main(){
boost();
cin >> n;
FR(i, n){
int a, b, c;
cin >> a >> b >> c;
vec.pb({a, b, c});
xs.pb(a);
ys.pb(b);
}
xs.pb(0);
ys.pb(0);
UNIQUE(vec);
UNIQUE(xs);
UNIQUE(ys);
for(auto [x, y, z] : vec){
x = lbv(xs, x);
y = lbv(ys, y);
compr.pb({x, y});
arr[x][y] = max(arr[x][y], z);
}
FOR(i, 1, MN) FOR(j, 1, MN){
arr[i][j] = max(arr[i][j], arr[i-1][j]);
arr[i][j] = max(arr[i][j], arr[i][j-1]);
}
int ans = -1;
n = SZ(vec);
FR(i, n) FR(j, n){
if(vec[i][1] >= vec[j][1] || vec[j][0] >= vec[i][0]) continue;
int mx = vec[i][0];
int my = vec[j][1];
int mz = arr[compr[j].fs-1][compr[i].sn-1];
if(mz > vec[i][2] && mz > vec[j][2]) ans = max(ans, mx+my+mz);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
62988 KB |
Output is correct |
2 |
Incorrect |
95 ms |
63000 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
62988 KB |
Output is correct |
2 |
Incorrect |
95 ms |
63000 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
63052 KB |
Output is correct |
2 |
Incorrect |
91 ms |
63040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
63052 KB |
Output is correct |
2 |
Incorrect |
91 ms |
63040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
63052 KB |
Output is correct |
2 |
Incorrect |
91 ms |
63040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
63052 KB |
Output is correct |
2 |
Incorrect |
91 ms |
63040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
62988 KB |
Output is correct |
2 |
Incorrect |
95 ms |
63000 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |