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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
struct node {
node *l = nullptr;
node *r = nullptr;
ll mx;
node(ll x = -inf) : mx(x) {}
};
const ll L = -1e14 - 2e9;
const ll R = +1e14 + 2e9;
inline void upd(node *&v, ll vl, ll vr, int pos, ll x) {
if (!v) v = new node();
chmax(v->mx, x);
if (vl == vr) return;
ll m = vl + vr >> 1;
if (pos <= m) upd(v->l, vl, m, pos, x);
else upd(v->r, m + 1, vr, pos, x);
}
inline ll get(node *v, ll vl, ll vr, ll l, ll r) {
if (!v || l > r) return -inf;
else if (vl == l && vr == r) return v->mx;
ll m = vl + vr >> 1;
ll a = get(v->l, vl, m, l, min(r, m));
ll b = get(v->r, m + 1, vr, max(l, m + 1), r);
return max(a, b);
}
node *rt = nullptr;
inline void upd(int pos, ll x) { upd(rt, L, R, pos, x); }
inline ll get(ll l, ll r) { return get(rt, L, R, l, r); }
inline void solve() {
int n;
cin >> n;
ve<ll> x(n), e(n), c(n);
for (int i = 0; i < n; ++i) cin >> x[i] >> c[i] >> e[i];
ve<ll> p1(n), p2(n);
for (int i = 0; i < n; ++i) {
p1[i] = e[i], p2[i] = c[i];
if (i) p1[i] += p1[i - 1], p2[i] += p2[i - 1];
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ll val = x[i] - (!i ? 0 : p1[i - 1]);
upd(val, !i ? 0 : -p2[i - 1]);
chmax(ans, get(val - e[i], R) + p2[i]);
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while (q--) solve();
cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
Compilation message (stderr)
divide.cpp: In function 'void upd(node*&, long long int, long long int, int, long long int)':
divide.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | ll m = vl + vr >> 1;
| ~~~^~~~
divide.cpp: In function 'long long int get(node*, long long int, long long int, long long int, long long int)':
divide.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | ll m = vl + vr >> 1;
| ~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |