This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
set<pll> S = {{-2, -1}, {-1, -2}};
ll X = -1, Y = -1;
auto p = ++S.begin();
void add(ll x, ll y)
{
if (x < X) {
S.insert({x, y});
Y = max(Y, y);
} else if (x == X && y <= p->second) {
S.insert({x, y});
} else {
auto p2 = S.insert({x, y}).first;
auto p2l = p2; --p2l;
if (p2l->second > p2->second || Y > p2->second) {
Y = max(Y, p2l->second);
X = p2->first;
p = p2;
} else {
auto p2r = p2; ++p2r;
if (p2r != S.end() && (p2->second > p2r->second || Y > p2r->second)) {
Y = max(Y, p2->second);
X = p2r->first;
p = p2r;
}
}
}
for (;;) {
auto p2 = p; ++p2;
ll newY = max(Y, p->second);
if (p2 == S.end() || p2->second >= newY)
break;
p = p2;
Y = newY;
X = p->first;
}
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n;
cin >> n;
map<ll, vector<pll>> mp;
Loop (i,0,n) {
ll x, y, z;
cin >> x >> y >> z;
mp[z].push_back({x, y});
}
ll ans = -1;
for (auto &[z, vec] : mp) {
for (auto [x, y] : vec) {
if (X > x && Y > y)
ans = max(ans, X+Y+z);
}
for (auto [x, y] : vec)
add(x, y);
}
cout << ans << '\n';
}
# | 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... |