This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I stand with PALESTINE
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> x(n), g(n), d(n), best(n);
for (int i = 0; i < n; i++) cin >> x[i] >> g[i] >> d[i];
vector<ll> pref_g(n);
for (int i = 0; i < n; i++) pref_g[i] = (i > 0 ? pref_g[i - 1] : 0ll) + g[i];
ll ans = 0, sum_d = 0;
set<pair<ll, int>, greater<>> need;
for (int i = 0; i < n; i++) {
sum_d += d[i];
need.emplace(x[i] - x[0] - sum_d, i);
}
sum_d = 0;
for (int i = 0; i < n; i++) {
if (i) best[i] = best[i - 1];
auto it = need.lower_bound(make_pair(x[i] - x[0] - sum_d, (int) 1e9));
while (it != need.end()) {
best[i] = max(best[i], it->second);
need.erase(it);
it = need.lower_bound(make_pair(x[i] - x[0] - sum_d, (int) 1e9));
}
// cout << i << ' ' << pref_g[best[i]] - (i > 0 ? pref_g[i - 1] : 0) << endl;
ans = max(ans, pref_g[best[i]] - (i > 0 ? pref_g[i - 1] : 0));
sum_d += d[i];
}
cout << ans;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q = 1;
// cin >> q;
while (q--) {
solve();
cout << '\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... |